Docker#
Docker Terminology#
Images - The blueprints of our application which form the basis of containers.
Containers - Created from Docker images and run the actual application. A list of running containers can be seen using the docker ps command. Docker Daemon - The background service running on the host that manages building, running and distributing Docker containers. The daemon is the process that runs in the operating system to which clients talk to.
Docker Client - The command line tool that allows the user to interact with the daemon.
Docker Hub - A registry of Docker images. You can think of the registry as a directory of all available Docker images. If required, one can host their own Docker registries and can use them for pulling images.
Using Docker#
Search for remote image#
docker search ubuntu # will search for ubuntu distrib
Install & Run Linux distribution #
docker pull debian # will install debian
docker pull ubuntu:16.04
docker pull centos
List local Docker images #
docker images
Run Docker image #
To run in interactive mode, use flag -i
docker run -it IMAGE /bin/bash
docker run -it ubuntu:trusty /bin/bash
docker run -it ubuntu:16.04
Remove Docker image or containers (force deletion) #
docker rmi -f IMAGE_ID
docker rmi $(docker images -a -q) # WARNING!!! This will remove all images
docker rm $(docker ps -a -f status=exited -q) # WARNING!!! This will remove all containers
Save a Docker image #
The example below shows how to install useful items on a standard ubuntu image, and then save the image locally.
# launch docker
docker pull ubuntu:16.04
docker run ubuntu:16.04
# inside image
apt-get update
yes | apt install git curl bzip2
# open another Terminal
# list current docker images
docker ps -a
# save container as new image
docker commit <container_id> your_name/ubuntu:16.04
Build Docker container from Dockerfile #
Create a Dockerfile by running `touch Dockerfile`
Inside the Dockerfile write the following (items below are just given as an example):
FROM centos:latest
RUN yum -y update \
&& yum -y install git bzip2 gcc wget which mesa-libGL unzip \
&& yum clean all
# Fetch SCT from source and install (at root directory)
RUN git clone https://github.com/neuropoly/spinalcordtoolbox.git sct; \
cd sct; \
yes | ./install_sct
# Add SCT executable to the system env
ENV PATH "/sct/bin:${PATH}"
Build docker image: `docker build -t <container_id> .`
Run it: `docker run -it <container_id>`
Run with DISPLAY redirection #
In order to run scripts with GUI you need to allow X11 redirection:
Install XQuartz X11 server and run it.
In preferences, check βAllow connections from network clientsoption inXQuartz` settings.
Quit and restart XQuartz.
In XQuartz window xhost + 127.0.0.1
In your other Terminal window, run:
On OSX: `docker run -e DISPLAY=host.docker.internal:0 -it <CONTAINER_ID>`
On Linux: `docker run -ti βrm -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix <CONTAINER_ID>`
Copy file into container #
# list container
docker ps
# copy file
docker cp <file> <CONTAINER ID>:<PATH_DEST>/<file>
Examples of Docker builder: