https://docs.docker.com/install/linux/docker-ce/ubuntu/
- Update the apt package index:
$ sudo apt-get update
- Add Docker’s official GPG key:
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
- Use the following command to set up the stable repository.
$ sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
Install the latest version of Docker Engine - Community and containerd
$ sudo apt-get update && sudo apt-get install docker-ce docker-ce-cli containerd.io
https://github.com/NVIDIA/nvidia-docker
下面只适合docker version>=19.03
# Add the package repositories
distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add -
curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list
sudo apt-get update && sudo apt-get install -y nvidia-container-toolkit
sudo systemctl restart docker
distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.repo | sudo tee /etc/yum.repos.d/nvidia-docker.repo
sudo yum install -y nvidia-container-toolkit
sudo systemctl restart docker
Ubuntu:
$ sudo service docker start
CentOS:
$ sudo systemctl start docker
查看所有images
docker images
删除docker image
docker rmi <image> ## image name or id
从Dockerhub或其他registry拉取一个image
docker pull <image>
docker pull ubuntu:16.04
sudo docker run hello-world #以root启动的docker daemon , 启动docker image也需root
启动一个ubuntu docker ,并进入bash
sudo docker run -it ubuntu bash
直接启动docker image
docker run -it <your-image>
nvidia runtime
docker run --runtime=nvidia -it <image> # docker < 19.03
docker run --gpus all -it <image> # docker >=19.03
挂载 host dir
docker run -v /host/dir:/container/dir <image>
端口映射
docker run -p hostport:container_port <image>
启动时设置环境变量
docker run -e RACV_DATA_PART=3 <image>
设置work_dir
docker run -w /work_dir
使用主机的网络
docker run --network host xxx
查看所有container
docker ps -a
docker ps -a -q ## 只看containerID
删除docker container
docker rm container_name
docker rm $(docker ps -a -q)
docker container logs containerID
docker exec -it containID /bin/bash
docker container stop containID
docker container rm containID
https://medium.com/@betz.mark/ten-tips-for-debugging-docker-containers-cde4da841a1d
docker logs
exec 只能在container running时可用,若container启动就崩溃,无法使用
https://docs.docker.com/engine/getstarted/step_four/
https://docs.docker.com/engine/reference/builder/
DockerHub上一些官方image:
FROM library/ubuntu:14.04.4
FROM nvidia/cuda:9.0-cudnn7-devel-ubuntu16.04 ##
公司自己的hub如:
FROM docker-registry.xxx.virtual/library/centos7:1.4
FROM docker-registry.xxx.virtual/docker/ubuntu:14.04.3
多条命令
CMD /etc/init.d/nullmailer start ; /usr/sbin/php5-fpm
设置进入bash的环境变量
https://docs.docker.com/engine/reference/run/
RUN pip install numpy
$ docker build -t nginx_image PATH
PATH is required, context path, for ADD or COPY command
-t target name
-f dockerfile name
如:
$ docker build -t robotarm:0.2 . -f robotarm_algorithms/Dockerfiles/Dockerfile
docker login reg.xxx.com
sudo docker login reg.xxx.com ## 有的登陆失败是由于没有用sudo
docker logout reg.xxx.com
sudo docker tag maskrcnn-benchmark:0.2 reg.xxx.com/cv/maskrcnn-benchmark:0.2
同样的image 会多出一条记录:
REPOSITORY TAG IMAGE ID CREATED SIZE
maskrcnn-benchmark 0.2 edfb8cb7c2a1 12 minutes ago 5.85GB
reg.xxx.com/ocr/maskrcnn-benchmark 0.2 edfb8cb7c2a1 12 minutes ago 5.85GB
sudo docker push reg.xxx.com/cv/maskrcnn-benchmark:0.2
https://docs.docker.com/install/linux/linux-postinstall/
- Create the docker group.
$sudo groupadd docker
- Add your user to the docker group.
$sudo usermod -aG docker $USER
- Logout and log back in so that your group membership is re-evaluated.