Memorandum docker command

Command template

Run docker and mount
$ nvidia-docker run --rm -it -v `pwd`:`pwd` -w `pwd` xxx/ubuntu:latest /bin/bash

Remove image
$ docker rmi ubuntu:latest

Remove container
$ docker rm CONTAINER_ID

Save container -> image
$ docker commit CONTAINER_ID ubuntu:latest2

Save image -> image
$ docker tag IMAGE_ID ubuntu:latest2

Run container

When CPU,
$ docker run --rm -it -v `pwd`:`pwd` -w `pwd` --net host -e DISPLAY=$DISPLAY -v $HOME/.Xauthority:/root/.Xauthority ubuntu:latest /bin/bash
When GPU,
$ nvidia-docker run --rm -it -v `pwd`:`pwd` -w `pwd` --net host -e DISPLAY=$DISPLAY -v $HOME/.Xauthority:/rot/.Xauthority ubuntu:latest /bin/bash

--- i ... Connect the standard input of the container and the input of the host --- t ... Connect the standard output of the container and the output of the host --- rm ... Erase when the container is closed --- v [Absolute host path]: [Absolute container path] ... Mount --- w [absolute path] ... Directory to run on the container ---- net host ... Use the network stack of the host on the container (?) --- e ... Set environment variables ---- net host -e DISPLAY = $ DISPLAY -v $ HOME / .Xauthority: /root/.Xauthority ... Magic for using GUI in container

Use GUI app (from Terminal on Mac)

$ brew cask install xquartz

Add the following to bash_profile

export DISPLAY_MAC=`ifconfig en0 | grep "inet " | cut -d " " -f2`:0
defaults write org.macosforge.xquartz.X11 nolisten_tcp -boolean false

function startx() {
  if [ -z "$(ps -ef|grep XQuartz|grep -v grep)" ] ; then
    open -a XQuartz

This command when starting the container. Pay attention to DISPLAY.

$ docker container run -it -e DISPLAY=${DISPLAY_MAC} ubuntu:18.04

Save container to image

Save container to new image

$ docker commit [CONTAINER_ID] [New_Repository]:[New_Tag]

Save image to new image

$ docker tag [IMAGE_ID] [New_Repository]:[New_Tag]

Put the container in the background

Container to background

Ctl + p in the terminal and ctl + q

Background container to front

$ docker attach [Container_ID]

Erase container

$ docker rm [Container_ID]

Remove all contatiner,

$ docker rm $(docker ps -a -q)

Erase image

$ docker rmi [Repository]:[Tag]
$ docker rmi [Image_ID]

Forcibly erase

$ docker rmi -f [Repository]:[Tag]

image list display

Show only child image

$ docker images

Also show parent image

$ docker images -a

Container list display

$ docker ps -a

Save image to Docker Hub

  1. Create a Docker Hub red
  2. Command below in the terminal
$ docker login
$ docker push [DockerHub's_username]/[Repository]:[Tag]
$ docker logout

Add user to Docker group

Check group

$ cat /etc/group | grep docker

Add user

$ sudo usermod -aG docker [User_Name]

Download an existing image

Ubuntu latest

$ docker pull ubuntu

Ubuntu latest for GPU

$ docker pull nvidia/cuda

Ubuntu with Cuda-8.0

$ docker pull nvidia/cuda:8.0-devel

Create image from image file

$ docker build -t [Repository]:[Tag] -f [Dockerfile_path] ./

Recommended Posts

Memorandum docker command
Docker command memorandum
Docker command
Docker memorandum
Docker memorandum
Technical memorandum (Docker)
Docker command list
Docker command memo
docker basic command
Docker command summary
[Docker] Command summary
[Docker] Command list
Docker Machine (personal memorandum)
Docker Machine command memo
docker error delete command
docker command personal summary
Docker command cheat sheet
Docker network (personal memorandum)
Decomposing the Docker run command. .. ..
Docker Compact Manual (1: Basic / Basic Command)
docker memo
Easy installation of Docker with snap (1 command)
kubernetes + docker
spring × docker
About Docker
Grant docker command execution permission to ec2-user
Launch docker container on EC2 (personal memorandum)
Command Pattern
MyBatis memorandum
Docker Intellij
Java memorandum
Docker basics
Rails memorandum
Error memorandum
Jaba Jaba Memorandum
Docker installation
JavaFx memorandum
About Docker
JAVA memorandum
JUnit memorandum
Try to use docker command without sudo.
Gradle Memorandum
Understand Docker
thymeleaf memorandum
Command docker-compose
Building a CICD pipeline using Docker (personal memorandum)
Environment construction command memo with Docker on AWS
[Laravel] Command memorandum until the start of the project
Data management using volume in Docker (personal memorandum)
Command to stop or delete all Docker resources