Docker: How does this (not) work?

I am trying to create a docker image which runs an sql server. For this purpose I did the following steps on a Windows machine.

  1. Run a mysql container to copy an init file into the virtual machine (not sure whether this step is actually necessary):

  2. Building a compiled application with Docker
  3. permission denied, mkdir in container on openshift
  4. Performance of IBM Containers Volumes
  5. Docker - MySQL containers on using the same volume of a data-only container
  6. apt-get update is not working inside docker container
  7. how to create an All-In-One docker image using sbt-docker and sbt-assembly
  8. docker run -i centurylink/mysql /bin/bash -c 'cat > table.sql' < /c/Users/bastian/Documents/docker/table.sql
  9. Create an image from the resulting container:

    docker commit ID mysql/with-table
  10. Run the image in order to initialize the database:

    docker run -d -it -p 3306:3306 -v /c/Users/bastian/Documents/docker/mysql:/mysql -e MYSQL_DATABASE='google' -e MYSQL_USER='foo' -e MYSQL_PASSWORD='bar' MYSQL_ROOT_PASSWORD='xxx' mysql/with-table

Now I have the follwing questions:

  1. When I execute docker inspect ID3 the output contains the command:

    "Cmd": [
         "cat \u003e table.sql"

    Does this mean that the copy command is executed and not the mysql server? How do I see which command will actually be executed?

  2. If I try to connect to the mysql server on the host machine:

    $ boot2docker ip 2> /dev/null
    $ mysql -h -p 3306
    Enter password: ***                        // I enter xxx here

    I get the following error message:

    ERROR 2003 (HY000): Can't connect to MySQL server on '' (10061)

    Any idea what the reason might be?

EDIT: So, I just removed the first steps and instead ran the centurylink/mysql image directly. If I do this and change the mysql line to $ mysql -h -p -u root (or -u foo) the connection works. Thus, the mysql line is erroneous and the mysql server is actually not started correctly when steps 1 and 2 are performed. Do you know the reason for this?

  • Best practice using ALB
  • Installing rbenv on docker ubuntu/debian
  • Confused about volumes_from and volumes usage in docker-compose.yml
  • Docker compose on docker swarm cluster separate containers on separate nodes
  • How to make a docker container directory accesible from host?
  • Docker container with MySQL not writing in the log file
  • One Solution collect form web for “Docker: How does this (not) work?”

    When you run a container with docker run some_image some_command, you’ve given it a command to run. In your case (step 1) this command was /bin/bash -c 'cat > table.sql'. Then in step 2 you committed that command to a new image. So your image runs that command instead of mysql.

    Maybe look at docker exec to do the futzing around to initialize. Or mount the data as a ‘Docker Volume’.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.