- Update the
apt
package index:
$ sudo apt-get update
- Install the necessary packages to allow
apt
to use a repository over HTTPS:
$ sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common
- Add Docker’s official GPG key:
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
Verify that you now have the key with the fingerprint:
$ sudo apt-key fingerprint 0EBFCD88
pub rsa4096 2017-02-22 [SCEA]
9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88
uid [ unknown] Docker Release (CE deb) <docker@docker.com>
sub rsa4096 2017-02-22 [S]
- Set up the stable repository:
$ sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
- Install the latest version of Docker Engine:
$ sudo apt-get update
$ sudo apt-get install docker-ce docker-ce-cli containerd.io
- Verify that Docker Engine - Community is installed correctly by running the hello-world image:
$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
ca4f61b1923c: Pull complete
Digest: sha256:ca0eeb6fb05351dfc8759c20733c91def84cb8007aa89a5bf606bc8b315b9fc7
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
...
- Run
docker image ls
to list the hello-world image that you downloaded to your machine:
$ sudo docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest fce289e99eb9 15 months ago 1.84kB
- You can check the status of all the containers using the below command:
$ sudo docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2eeed464cd9f hello-world "/hello" 2 minutes ago Exited (0) 2 minutes ago objective_perlman
89bb80313ac4 mysql:5.7 "docker-entrypoint.s…" 15 minutes ago Up 15 minutes 0.0.0.0:3306->3306/tcp, 33060/tcp vldb-mysql
- You can stop one or more running containers:
$ sudo docker stop [container-name]
Start a MySQL instance is simple:
$ sudo docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=pw -d mysql:5.7
some-mysql
: The name you want to assign to your containerpw
: The password to be set for the MySQL root usermysql:5.7
: The tag specifying the MySQL version you want. See the manual for relevant tags.
You can use docker-compose
to run a MySQL container.
- Download and install the desired version of
docker-compose
. You can check all the released versions in the GitHub:
$ sudo curl -L https://github.com/docker/compose/releases/download/1.26.0-rc3/docker-compose-Linux-x86_64 -o /usr/local/bin/docker-compose
$ sudo chmod +x /usr/local/bin/docker-compose
$ ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
$ sudo docker-compose --version
docker-compose version 1.26.0-rc3, build 46118bc5
- Define the services that make up your app in
docker-compose.yml
so they can be run together in an isolated environment. For example, mydockers-compose.yml
looks like this:
version: '3.1'
services:
db:
image: mysql:5.7
container_name: vldb-mysql
ports:
- 3306:3306
volumes:
- /home/mijin/test_data:/var/lib/mysql
- /home/mijin/mysql-conf:/etc/mysql/conf.d
environment:
MYSQL_ROOT_PASSWORD: "pw"
- Run
docker-compose up
. Then Compose starts and runs the MySQL app:
$ sudo docker-compose up -d
Creating vldb-mysql ... done
The mounted directory in the host system can be used as a data directory on MySQL in Docker. Add volumes
in the yaml file (dockers-compose.yml
):
db:
image: mysql:5.7
...
volumes:
- /home/mijin/test_data:/var/lib/mysql
...
/home/mijin/test_data
: The SSD-mounted directory in host system/var/lib/mysql
: The data directory for MySQL in Docker
We can also map a customized my.cnf
to MySQL container.
- Create a new
my.cnf
file:
$ vim /home/mijin/mysql-conf/my.cnf
...
- Modify
dockers-compose.yml
to mapmysql-conf
directory in host system intoconf.d
directory in Docker:
db:
image: mysql:5.7
...
volumes:
- /home/mijin/mysql-conf:/etc/mysql/conf.d
...
- Run
docker-compose up
:
$ sudo docker-compose up -d
Creating vldb-mysql ... done
- Run the below command to connect to the created container's bash:
$ sudo docker exec -it vldb-mysql bash
- Check the modified server variable in MySQL:
root@89bb80313ac4:/# mysql -uroot -p -e "show variables like '%log_files%'"
+---------------------------+-------+
| Variable_name | Value |
+---------------------------+-------+
| innodb_log_files_in_group | 3 |
+---------------------------+-------+
The value of innodb_log_files_in_group
was changed from 2 (default value) to 3 (the value set in mysql-conf/my.cnf
).