Understanding a complex docker command

I was just going through this tutorial online and the author , uses the following command along the way:

sudo docker run –name my_sql -e MYSQL_ROOT_PASSWORD=mysecretpassword –volumes-from my_datastore -d mysql

  • Run Docker on Windows without virtualization
  • Proxy_pass from foo.website.com to localhost:xxxx using nginx on docker - not localhost on physical machine
  • Docker terminology confusion
  • How to run Rails migrations and seeding in Amazon Elastic Beanstalk single container Docker environment
  • Ubuntu and updating Docker
  • Docker run error: could not create session key: too many links
  • So my understanding of the above command is as follows there is a specific name given to the image and after that there is a environment variable being passed and after there is a --volumens-from command being executed , -d indicates that the container should be run in the background .

    I am not sure what i mysql is at the end.

    My question is as following:

    Docker uses the following syntax:

    docker [OPTIONS] COMMAND [arg...] 

    in the command that i have highlighted what are the [OPTIONS] what is the COMMAND and what are the [arg...] ? also what is mysql doing in the end of the command ?

    Thank you.


  • Dockerfile CMD `command not found`
  • How to use run deck service from local browser using up address?
  • How to version control Docker containers' data volumes?
  • cannot reach web app from docker host (not docker-machine)
  • Always ask password on local file when modified file when ran docker container
  • How to share a folder between my Mac and a Docker container
  • 2 Solutions collect form web for “Understanding a complex docker command”

    Great question, and you’re correct on your statements.

    The naming convention is as follows:

    The name of the container

    --name my_sql

    Environment Variable(s) – You can add as many as you want, each with an additional ‘-e’ directive

    -e MYSQL_ROOT_PASSWORD=mysecretpassword 

    Directive to use a volume from a different container

    --volumes-from my_datastore 

    Run in the background


    The name of the Docker image that you’re using to make a container


    You could even use something like mysql:latest (the :latest is a tag that would pull the most recent version of that image).

    Hope that helps!

    Two things make it hard to understand for newer, let me explain

    First, what’s inside of docker image mysql.

    There is no Dockerfile in hub.docker.com for image mysql. So if you don’t understand what is running in container with this image, you can run below command to get details

    $ alias dfimage='docker run -v /var/run/docker.sock:/var/run/docker.sock --rm centurylinklabs/dockerfile-from-image'
    $ dfimage mysql
    ADD file:f7eb3ddd8c7f33332cd94564ec171306ffa490836953449b9b9c506085ec8745 in /
    CMD ["/bin/bash"]
    RUN groupadd -r mysql && useradd -r -g mysql mysql
    RUN mkdir /docker-entrypoint-initdb.d
    RUN apt-get update && apt-get install -y perl --no-install-recommends && rm -rf /var/lib/apt/lists/*
    RUN apt-key adv --keyserver ha.pool.sks-keyservers.net --recv-keys A4A9406876FCBD3C456770C88C718D3B5072E1F5
    RUN echo "deb http://repo.mysql.com/apt/debian/ wheezy mysql-${MYSQL_MAJOR}" > /etc/apt/sources.list.d/mysql.list
    RUN {       echo mysql-community-server mysql-community-server/data-dir select '';      echo mysql-community-server mysql-community-server/root-pass password '';       echo mysql-community-server mysql-community-server/re-root-pass password '';        echo mysql-community-server mysql-community-server/remove-test-db select false;     } | debconf-set-selections  && apt-get update && apt-get install -y mysql-server="${MYSQL_VERSION}"* && rm -rf /var/lib/apt/lists/*     && rm -rf /var/lib/mysql && mkdir -p /var/lib/mysql
    RUN sed -Ei 's/^(bind-address|log)/#&/' /etc/mysql/my.cnf   && echo 'skip-host-cache\nskip-name-resolve' | awk '{ print } $1 == "[mysqld]" && c == 0 { c = 1; system("cat") }' /etc/mysql/my.cnf > /tmp/my.cnf  && mv /tmp/my.cnf /etc/mysql/my.cnf
    VOLUME [/var/lib/mysql]
    COPY file:eebf5525e2e95ae059f8b5954a592e533f986fd2073741a1e0b7731ff2cb3860 in /entrypoint.sh
    ENTRYPOINT &{["/entrypoint.sh"]}
    EXPOSE 3306/tcp
    CMD ["mysqld"]

    So it exposed port 3306 and run the default command /entrypoint.sh mysqld if there is no --entrypoint option override it.


    • you can replace the entrypoint command with --entrypoint
    • you can run docker history mysql to get similar information, but not good enough.

    Second, how to understand --volumes-from

    --volumes-from is the volume in another container my_datastore, you should be fine to use similar dfimage to show its volume:

    docker inspect -f {{ .Volumes }} my_datastore

    with --volumes-from, the mysql container can access the data in another container.

    If you want to know more about --volumes-from, go though this document Managing data in containers

    For the rest options, you should be fine. If you have any question, let me know.

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