Docker Use Cases

スポンサーリンク

Docker Use cases

  • Pull docker image
  • Login DockerHub
  • Show Docker image list
  • Create (Run) container from image
  • Create (Run) container from image and Run command
  • Show container status
  • Show all docker container status
  • Restart exit container
  • Re-connect docker container
  • Attach Detached container
  • Commit and update Docker image
  • Save Docker image as
  • Delete Docker images (Local)
  • Delete Dangling images
  • Build docker image from Dockerfile
  • Show docker container details
  • Show docker container CPU info

Pull Docker image

docker pull <image>

ex)

docker pull ubuntu

Login DockerHub

docker login

Show Docker image list

docker images

Create (Run) container from image

docker run <image>

docker run ubuntu

Create (Run) container from image and Run command

docker run -it <image> <command>

docker run -it ubuntu bash

Show container status

docker ps

Show all docker container status

docker ps -a

docker ps is only active, -a contains all exit

Restart exit container

docker restart <container>

<container> is Container name or ID

docker restart xxxxx

Re-connect docker container

docker exec -it <container> bash

docker exec -it xxxxxx bash

Attach Detached container

docker attach <container>

docker attach xxxxxx

Commit and update Docker image

docker commit <container> <newimage>

docker commit xxxxx ubuntu:updated

ubuntu:updated.     ubuntu is image name,  updated is tag

Save Docker image as

docker tag <source> <target>

<source> is original docker image <target> is new name

docker tag ubuntu:updated dj110/newubuntu

dj110 is Dockerhub user ID
newubuntu is new docker repository name

By default, dst is Dockerhub, if you want to chang other repository

<hostname>:<port>/<username>/<repository>:<tag>

Push Docker image

Push Docker image to remote or local repository

docker push <images>

docker push dj110/newubuntu

By default, this is Docker hub.

Push image style is : <hostname>:<port>/<username>/<repository>:<tag>

Delete Docker images (Local)

docker rmi <image>

docker rmi dj110/neoubuntu

Delete Docker container

docker rm <container>

docker rm xxxxxx

Stop Docker container

docker stop <container>

docker stop xxxxxx

Delete Dangling images

docker system prune

Dangling images are layers that have no relationship to any tagged images (from Stackoverflow)

To use this commands, can delete multiple unused images in one command.

Build docker image from Dockerfile

docker build -t <name> <directory>

<name> is image name

<directory> is Docker context. (target directory which has Dockerfile)

docker build -t new-ubuntu:latest .

Show docker container details

docker inspect <container>

docker inspect xxxxx

Show docker container CPU info

This is above command advanced

docker inspect xxxxx | grep -i cpu
Server
スポンサーリンク
Professional Programmer2

コメント