# Create the docker group. > sudo groupadd docker # Add your user to the docker group. > sudo usermod -aG docker $USER # Log out and log back in so that your group membership is re-evaluated. # If testing on a virtual machine, it may be necessary to restart the virtual machine for changes to take effect. # On a desktop Linux environment such as X Windows, log out of your session completely and thenlog back in. # 开启dockers服务 > sudo systemctl restart docker # Verify that you can run docker commands without sudo. > docker run hello-world
# Uninstall the Docker CE package: > sudo apt-get purge docker-ce # Images, containers, volumes, or customized configuration files on your host are not automatically removed. To delete all images, containers, and volumes: > sudo rm -rf /var/lib/docker
# create a container # --name: specify a name to container # format: docker run options image_id command > docker run -dt --name test image # Attaching a Shell to a Container > docker container exec -it test /bin/bash
GPU
1 2 3 4 5 6 7 8 9 10 11 12 13 14
# use gpu #### Test nvidia-smi with the latest official CUDA image $ docker run --gpus all nvidia/cuda:9.0-base nvidia-smi # Start a GPU enabled container on two GPUs $ docker run --gpus 2 nvidia/cuda:9.0-base nvidia-smi # Starting a GPU enabled container on specific GPUs $ docker run --gpus '"device=1,2"' nvidia/cuda:9.0-base nvidia-smi $ docker run --gpus '"device=UUID-ABCDEF,1"' nvidia/cuda:9.0-base nvidia-smi # Specifying a capability (graphics, compute, ...) for my container # Note this is rarely if ever used this way $ docker run --gpus all,capabilities=utility nvidia/cuda:9.0-base nvidia-smi
3. save a container as an image
The commit\export operation will not include any data contained in volumes mounted inside the container.
在没有访问外网权限的内网区域内, 可方便在不同host上面进行拷贝移植
1 2 3 4 5 6 7
# Create a tar file from a container’s changes > docker export container > bak.tar # reload, create a new image > cat bak.tar | docker import - [REPOSITORY[:TAG]] ## > docker import bak.tar [REPOSITORY[:TAG]]