docker-compose.yml ubuntu 1

docker-compose.yml ubuntu

version: '3.7'
services:
 webserver:
  image: nginx:alpine
  ports:
   - "8000:80"
  volumes:
   - ./app:/usr/share/nginx/html

Here is what the above code is Doing:
1. We are using the nginx:alpine image.
2. We are exposing port 80 of the container to port 8000 of the host machine.
3. We are mounting the app directory of the host machine to the /usr/share/nginx/html directory of the container.

Now, let’s run the following command to build the image:

$ docker build -t webserver-image:v1 .

Sending build context to Docker daemon 2.048kB
Step 1/3 : FROM nginx:alpine
—> 6d1ef012b567
Step 2/3 : COPY app /usr/share/nginx/html
—> Using cache
—> bf9a8f8f8f8f
Step 3/3 : EXPOSE 80
—> Using cache
—> f8f8f8f8f8f8
Successfully built f8f8f8f8f8f8
Successfully tagged webserver-image:v1

Now, let’s run the following command to run the container:

$ docker run -d -p 8000:80 webserver-image:v1

Unable to find image ‘webserver-image:v1’ locally
v1: Pulling from library/webserver-image
8f8f8f8f8f8f: Pull complete
Digest: sha256:f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8
Status: Downloaded newer image for webserver-image:v1
f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f

Similar Posts