How can I get started with Docker?

Posted in Add your tools by Zoidberg Wed Mar 02 2016 22:07:54 GMT+0000 (UTC)·1·Viewed 695 times

I'm new to Docker. How can I get started? Any helpful tips?
Gaurav Kaushik
Mar 2, 2016

To start with, here's a <b>key</b> for Docker semantics:

<b>IMAGE</b> <br \>

  • e.g. rfranklin/rstatsdev <br \>
  • a read-only Docker image that you can pull and run <br \>
  • can have a TAG (e.g. rfranklin/rstatsdev:0.1) <br \>
  • identified by <repository>/<name>[:<tag>]

<b>CONTAINER</b> <br \>

  • a running instance of an image that you can read and write to <br \>
  • each instance has a unique CONTAINER_ID

<b>COMMAND</b> <br \>

  • a general command <br \>
  • e.g. /bin/bash

<b>REGISTRY</b> <br \>

  • a store for Docker images <br \>
  • e.g. Docker Hub or the CGC Image Registry
How to modify a container, commit the changes to a new image, and push that image to DockerHub:
  1. Boot up the Docker Quickstart Terminal, this will automatically fire up the docker daemon

  2. docker login

    • put in your credentials or use stored credentials if they exist
  3. docker images

    • get a list of all your Docker images
  4. `docker run -ti <IMAGE>

    • e.g
      docker run -ti rfranklin/pythondev # access command line of container
    • the -i flag allows you to use your new container interactively
    • the -t flag allocates a pseudo-TTY or pseudoterminal (to execute commands)
  5. docker ps -a

    • after exiting the container, you can retrieve its id with the above command
  6. docker commit <NEW CONTAINER_ID> <IMAGE>

    • commit the container to a new image
    • e.g docker commit f692sd3s4e1b rfranklin/pythondev:v2
    • e.g docker commit f692sd3s4e1b
  7. docker push <IMAGE:VERSION>

    • finally, push your new image

Run a local container interactively:

docker run -ti IMAGE

Look up info about container:

docker inspect IMAGE

Mount a local folder onto your container:

docker run -v /foo:/bar IMAGE

  • take /foo in your local machine and make available as /bar in your container

Fix an error with the Docker Daemon:

docker-machine restart default && eval ($docker-machine env default)

Retag an image:

docker images

  • get the IMAGE_ID for your image of interest
  • docker tag <IMAGE_ID> <IMAGE>
  • e.g. docker tag sha:4141532

Copy local file into container and then save files as a new image:



docker cp a4a27b7d1944:/

  • this will copy the files to that specific container

docker commit a4a27b7d1944 rfranklin/rstatsdev:v2

  • now the changes you made (copying the files over) will persist to this new image. You can run this image to test your analyses.
Markdown is allowed