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. Creating an easily-distributable dev environment - Docker/Vagrant? [closed]
  3. Docker diff isn't showing changes to new files
  4. MySQL EF6 with MVC5 and DNX
  5. Docker volume mounting shows empty directory with a linux mounted directory
  6. Docker doesn't resolve hostname
  7. See the installation log in oracle silent installation on windows
  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": [
         "/bin/bash",
         "-c",
         "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
    192.168.59.103
    
    $ mysql -h 192.168.59.103 -p 3306
    Enter password: ***                        // I enter xxx here
    

    I get the following error message:

    ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.59.103' (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 192.168.59.103 -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?

  • How to get contents generated by a docker container on the local fileystem (minimal failing example)
  • Update Docker image and container from Jenkins
  • docker not opening ports on OSX
  • I just installed docker, but running “hello world” failed, it doesn't download image?
  • is there a way to crash a docker container deliberately?
  • How to run Alfresco Bundled Installer on Docker?
  • 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.