Create a Docker image with docker build command

This post is a personal note for building mysql container using Docker.
Update Docker daemon
In my case, the version of docker was old, so I downloaded docker for Mac from the official website and updated docker daemon.
Check docker version.
1docker version
2
3Client:
4 Version: 1.13.0
5 API version: 1.25
6 Go version: go1.7.3
7 Git commit: 49bf474
8 Built: Wed Jan 18 16:20:26 2017
9 OS/Arch: darwin/amd64
10
11Server:
12 Version: 1.13.0
13 API version: 1.25 (minimum version 1.12)
14 Go version: go1.7.3
15 Git commit: 49bf474
16 Built: Wed Jan 18 16:20:26 2017
17 OS/Arch: linux/amd64
18 Experimental: trueEdit Dockerfile
Create a simple Dockerfile as follows and place it at the project root.
I use offical mysql image in this time.
1FROM mysql
2MAINTAINER soudegesu
3
4RUN echo "finished setup !!"Build docker image
I ran the command at project root where the Dockerfile was located, docker should recognize Dockerfile.
1docker rmi soudegesu/mysql:0.0.1
2
3Untagged: soudegesu/mysql:0.0.1
4Deleted: sha256:5cdbd0f32baa9bd25e39532ae9e660e35c0d9e57740406536b05bb7dbfbd4226
5Deleted: sha256:b60d4e0b4ad869c06c6e874095d813c5d91990f0266897163d714b201501b577
6
7docker build -t soudegesu/mysql:0.0.1 .
8
9Sending build context to Docker daemon 57.86 MB
10Step 1/3 : FROM mysql
11 ---> 7666f75adb6b
12Step 2/3 : MAINTAINER soudegesu
13 ---> Using cache
14 ---> ebb2015c5850
15Step 3/3 : RUN echo "finished setup !!"
16...Start docker container
Start container with docker run command.
The following CLI options are often used for operating inside the container after the container startup.
-i:Keep STDIN open even if not attached-t:Allocate a pseudo-TTY
1docker run -it soudegesu/mysql:0.0.1 /bin/bash
2
3root@08671cc122c7:/#I can see that the official mysql docker image is running on Moby Linux.
1root@0e512378b63d:/# cat /proc/version
2
3Linux version 4.9.4-moby (root@1d811a9194c4) (gcc version 5.3.0 (Alpine 5.3.0) ) #1 SMP Wed Jan 18 17:04:43 UTC 2017Check whether the mysql command can be used. An error occurred.
1root@08671cc122c7:/# mysql
2
3ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)mysql is not running. I added the following CLI option and started it again.
1docker run --name soudegesu -e MYSQL_ROOT_PASSWORD=soudegesu -d soudegesu/mysql:0.0.1