Skip to main content

All the Docker commands I used last week.

Β· 2 min read
Xinyi Z.
Data Engineer

Last updated: 2019–05–22

Docker is one of the tools that as a data scientist should have in their software development pipeline. It is a platform for developers and sysadmins to develop, deploy, and run applications with containers. The underlying philosophy is that if it works on my machine it should work on yours.

If you haven’t had Docker on your machine, please jump to the end of this article >> Docker Installation.

Terminology#

A container is a runtime instance of an image β€” what the image becomes in memory when executed. It is launched by running an image. An image is an executable package that includes everything needed to run an application β€” the code, a runtime, libraries, environment variables and configuration files.

We can create an automated build that executes several instructions in succession with a Dockerfile, which is a text document that contains all the commands a user could call on the command line to assemble an image.

Just like there is GitHub for git, there is Docker Hub for Docker. Docker Hub is an open platform to share Docker images so that the next person can simply pull one for personal use.

Docker commands summary#

## Execute Docker imagedocker run --name [container-name] image-name # The container Names are randomly generated if not specified
# run with parametersdocker run -it ${DOCKER_USERNAME}/bertencoder β€” max_steps 80docker exec -it CONTAINERID bash #run bash on an existing container
## List imagesdocker images
## List Docker containers (running, all, all in quiet mode)docker container ls β€” all #all containsdocker container ls #the running onesdocker container ls -aq #all containers in quiet mode
## Removedocker kill $(docker ps -q) # you cannot remove a running container, so kill before removedocker rm $(docker ps -a -q)docker rmi $(docker images -q)docker build -t ${DOCKER_USERNAME}/bertencoder .docker build -t imagename .
# docker hub docker logindocker tag my_image $DOCKER_USER_ID/my_imagedocker push $DOCKER_USER_ID/my_imagedocker search -s 3 xinyi2016
## List Docker CLI commandsdocker container β€” help

Docker Installation#

sudo -s # (optional) run commands in rootcurl -fsSL get.docker.com -o get-docker.shsh get-docker.sh