Join our Discord Server
Getting Started

Lab 7: The ‘Up’ Command

Estimated reading: 2 minutes 96 views

The docker-compose up command help you to bring up a multi-container application, which you have described in your docker-compose file.

Pre-requisite:

Tested Infrastructure

Platform Number of Instance Reading Time
Play with Docker 1 5 min

Pre-requisite

  • Create an account with DockerHub
  • Open PWD Platform on your browser
  • Click on Add New Instance on the left side of the screen to bring up Alpine OS instance on the right side

Assignment

  • Create a docker-compose.yml with custom image
  • Build container and network
  • Bringup the containers

Create a docker-compose.yml with custom image

Setup environment

$ mkdir -p docker-compose/build
$ cd docker-compose/build

Now lets create the Dockerfile

FROM nginx:alpine
RUN echo "Welcome to Docker Workshop!" >/usr/share/nginx/html/index.html
CMD ["nginx", "-g", "daemon off;"]

Create a docker-compose.yml file

version: "3.7"
services:
  webserver:
    build:
      context: .
      dockerfile: Dockerfile
    image: webapp:v1
    container_name: Nginx
    ports:
      - "80:80"
  dbserver:
     image: mysql:5.7
     container_name: Mysqldb
     restart: unless-stopped
     ports:
       - "3306:3306"
     environment:
       MYSQL_ROOT_PASSWORD: Pa$$w0rd
       MYSQL_USER: test
       MYSQL_PASSWORD: Pa$$w0rd123
       MYSQL_DATABASE: test 
     volumes:
       - db_data:/var/lib/mysql
volumes:
  db_data:

Build container and network

Won’t start the container

$ docker-compose up --no-start
Creating network "build_default" with the default driver
Creating Nginx   ... done
Creating Mysqldb ... done

Checking the status

$ docker-compose ps
 Name               Command             State    Ports
------------------------------------------------------
Mysqldb   docker-entrypoint.sh mysqld   Exit 0        
Nginx     nginx -g daemon off;          Exit 0    

Bringup the containers

$ docker-compose up -d

NOTE: This will build the images and bringup the containers. -d option which will run the container in background.

Checking webserver respone

$ curl http://localhost
Welcome to Docker Workshop!

Checking dbserver respone

$ docker exec -it Mysqldb mysql -u root -p
Enter password: 

Rebuild the docker image and bring the stack up

$ docker-compose up -d --build
Share this Doc

Lab 7: The ‘Up’ Command

Or copy link

CONTENTS
Join our Discord Server