Docker Basic Command | Description |
---|---|
docker run hello-world |
Download the very small hello-world image and print a “Hello from Docker“ message |
docker images |
Get List of Docker Images |
docker search busybox |
Search the online Docker registry for a Image named busybox |
docker run -t -i busybox |
Create an instance (container) of 'busybox' image interactively |
docker run -t -i busybox:latest |
Create an instance with 'latest' tag value |
docker run -t -i busybox:1.0 |
Create an instance with '1.0' tag value |
docker ps --all |
List all containers |
docker start ab0e37214358 |
Relaunch a Container |
docker attach ab0e37214358 |
Attach local standard input, output, and error streams to a running container |
docker stop ab0e37214358 |
stop a running container |
docker search httpd |
Search Apache Web Server |
docker pull httpd |
download the httpd image |
docker run -d --name MyWebServer httpd |
Running the Container in Detached mode with name |
docker stop MyWebServer |
Stop the container named MyWebServer |
docker rm MyWebServer |
Remove container named MyWebServer |
docker run -d --name MyWebServer -P httpd |
Publish all exposed ports to random ports |
docker run -d --name MyWebServer -p 80:80 httpd |
Publish all exposed ports to specific port |
Docker Hub Command | Description |
---|---|
docker search java |
Searching for Images |
docker pull java |
Pulling an Image named 'Java' |
docker run java:latest |
Launching a Container |
docker images |
List all images |
docker pull ubuntu:latest |
Get an ubuntu image |
docker run -it --name mycontainer1 --rm ubuntu:latest |
Container is removed on termination |
docker run -it --name mycontainer1 ubuntu:latest |
Run local ubuntu image without rm flag |
docker ps -all |
List all container to see their ID |
docker commit mycontainer1 ynwd/ubuntu-git |
Committing your Image (change 'ynwd' with your own) |
docker run -it --name c1 ynwd/ubuntu-git |
Launching a Container from your Image (change 'ynwd' with your own) |
docker login |
Login to docker hub |
docker push ynwd/ubuntu-git |
Pushing the Image to the Docker Hub |
docker-compose logs --tail=0 --follow |
Print all container log |
docker rmi $(docker images | grep "^<none>" | awk "{print $3}") |
Remove untaged images |
docker start -ai container_name |
Start a stopped container |
Docker Private Registry | Description |
---|---|
docker pull registry |
pull down the ‘latest’ registry image |
docker run -d -p 5000:5000 --name localregistry registry |
Run the local Registry |
docker ps |
List container |
docker pull alpine |
Get an alpine image |
docker tag alpine:latest localhost:5000/alpine:latest |
Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE |
docker push localhost:5000/alpine:latest |
push this tagged image or container into the local registry |
docker rmi $(docker images -a -q) |
Docker Data Volumes | Description |
---|---|
docker run -it -v /data --name container1 busybox |
launch a container (named container1) in interactive mode and mount a volume |
docker inspect container1 |
inspect the container |
docker restart container1 |
restart container |
docker attach container1 |
attach container |
docker run -it --name container1 -v /Users:/datavol busybox/ # |
mount a host volume while launching a Docker container |
docker run -it --volumes-from container1 --name container2 busybox |
|
docker stop $(docker ps -a -q) |
One liner to stop |
docker rm $(docker ps -a -q) |
remove all of Docker containers |
docker build -t takacsmark/alpine-smarter:1.0 . |
Create image |