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. Docker build: unable to fetch archives
  3. Stack/Docker/IHaskell weird behaviour
  4. Couldn't find Docker Tool Window IntelliJ IDEA 2016.2.4 (Ultimate)
  5. “No such file or directory” what's wrong in this Dockerfile?
  6. Docker: use private layers without running instance of registry
  7. Error starting docker daemon
  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?

  • remote control nginx configuration
  • gcloud preview app setup-managed-vms gives errors - 500 Server Error: Internal Server Error
  • Docker HaProxy exposed ports
  • Connect to WordPress Docker Container
  • CrashLoopBackOff: Docker image not running on Kubernates ? (ImagePullBackOff)
  • Container command could not be invoked
  • 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.