Aim

In this tutorial we will be installing docker compose on Ubuntu-18.04

Step 1 : Download the docker compose binary

sudo curl -L "https://github.com/docker/compose/releases/download/1.26.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
  • If you want to install a different version then just replace the 1.26.2 in above command with the version that you want to install
  • The location of docker compose binary is /usr/local/bin/docker-compose

Step 2 : Make the binary executable

sudo chmod +x /usr/local/bin/docker-compose

Step 3 : Check if docker-compose is installed

  • we will try to check the version of docker compose installed
docker-compose version
  • we will get output like this but the content may differ
selftuts@node1:~$ docker-compose version
docker-compose version 1.26.2, build eefe0d31
docker-py version: 4.2.2
CPython version: 3.7.7
OpenSSL version: OpenSSL 1.1.0l  10 Sep 2019

Install MySQL-5.7 with docker compose

  • Create a mysql-docker-compose.yml file
touch mysql-docker-compose.yml
  • Put following contents inside the mysql-docker-compose.yml file
version: "3.7"
services:
  mysql:
    image: mysql:5.7
    container_name: mysql-5.7
    restart: always                       # always restart
    environment:
      MYSQL_DATABASE: 'test'              # name of database
      MYSQL_USER: 'sample'                # sample is the name of user
      MYSQL_PASSWORD: 'password'          # password for sample user
      MYSQL_ROOT_PASSWORD: 'password'     # password for root user
    ports:
      - '3306:3306'                       # host port 3306 is mapper to docker port 3306
    expose:
      - '3306'
    volumes:
      - ./mysql-db:/var/lib/mysql
  • Run the container in foreground mode
 docker-compose -f mysql-docker-compose.yml up
  • You can see some logs on your screen which will keep on printing
selftuts@node1:~$ docker-compose -f mysql-docker-compose.yml up
Creating network "selftuts_default" with the default driver
Pulling mysql (mysql:5.7)...
5.7: Pulling from library/mysql
6ec8c9369e08: Already exists
177e5de89054: Pull complete
ab6ccb86eb40: Pull complete
e1ee78841235: Pull complete
09cd86ccee56: Pull complete
78bea0594a44: Pull complete
caf5f529ae89: Pull complete
4e54a8bcf566: Pull complete
50c21ba6527b: Pull complete
68e74bb27b39: Pull complete
5f13eadfe747: Pull complete
Digest: sha256:97869b42772dac5b767f4e4692434fbd5e6b86bcb8695d4feafb52b59fe9ae24
Status: Downloaded newer image for mysql:5.7
Creating mysql-5.7 ... done
Attaching to mysql-5.7
mysql-5.7 | 2020-08-04 19:23:13+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.31-1debian10 started.
mysql-5.7 | 2020-08-04 19:23:13+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
mysql-5.7 | 2020-08-04 19:23:13+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.31-1debian10 started.
mysql-5.7 | 2020-08-04 19:23:14+00:00 [Note] [Entrypoint]: Initializing database files
mysql-5.7 | 2020-08-04T19:23:14.038328Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
mysql-5.7 | 2020-08-04T19:23:14.315136Z 0 [Warning] InnoDB: New log files created, LSN=45790
mysql-5.7 | 2020-08-04T19:23:14.370581Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
mysql-5.7 | 2020-08-04T19:23:14.455413Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: f13e7a61-d687-11ea-855f-0242ac120002.
mysql-5.7 | 2020-08-04T19:23:14.457930Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
mysql-5.7 | 2020-08-04T19:23:15.558748Z 0 [Warning] CA certificate ca.pem is self signed.
  • If you want to run the container in background mode then use the -d flag
docker-compose -f mysql-docker-compose.yml up -d

Happy Coding

5 1 vote
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x