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

  • Restrict Docker exposed port from only specific IP adresses
  • Access Docker forwarded port on Mac
  • Secure Admin must be enabled to access the DAS remotely - Acess Glassfish Admin Console with Docker
  • Store persistent data in docker container directory
  • Can I mount data to host filesystem from docker's VOLUME CREATE?
  • How to run docker images (nodejs server) without exiting
  • 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.

    Alex-z.

  • Adding Java to Boot2Docker Linux VM?
  • How to open swagger-ui using docker
  • accessing the docker container for rabbitmq from ubuntu host
  • Docker container: MongoDb Insufficient free space for journal files
  • how to limit number of streams when pulling docker image
  • Connection refused when trying to run Kong API Gateway using 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

    -d 
    

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

    mysql 
    

    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
    ENV MYSQL_MAJOR=5.6
    ENV MYSQL_VERSION=5.6.26
    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.

    Notes:

    • 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.