The Ultimate Stitcher!
Record Docker packaging conda environment + code & upload to your own Docker hub
1. Start by installing Docker
-
Install the yum tool
yum install -y yum-utils device-mapper-persistent-data lvm2 --skip-broken
-
Set docker image source
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
sed -i 's/download.docker.com/mirrors.aliyun.com\/docker-ce/g' /etc/yum.repos.d/docker-ce.repo
yum makecache fast
-
Install Docker
yum install -y docker-ce
-
First enter: sudo systemctl start docker, then enter: sudo systemctl enable docker
sudo systemctl start docker
sudo systemctl enable docker
Docker installation over
2. Package the Conda project into a mirror image
-
First install a miniconda-based image
docker pull continuumio/miniconda3
-
into the container
docker run --name test -idt continuumio/miniconda3
-d in -idt specifies the running mode of the container, allowing the docker service to run in the background.
-
Take a look at the list of containers
docker ps -a
-
Enter the test container and check the conda location
docker exec -it test /bin/bash
View conda location:
conda info --envs
After viewing, exit the container:
exit
-
Copy the local environment into docker in the local environment
After exiting the container, copy what needs to be packaged locally to docker in the local environment
docker cp /root/miniconda3/envs/你的conda环境 test:/opt/conda/envs
- /home/b/miniconda3/envs/pipe is the local environment that needs to be packaged
- test is the container name, and /opt/conda is the root directory of conda in the container.
-
Then enter the container to check whether the environment is copied successfully
docker exec -it test /bin/bash
conda info --envs
exit
-
Copy native code into docker in local environment
After exiting the container, copy the code to be packaged into docker in the local environment
docker cp /data/代码路径 test:/root/
docker exec -it test /bin/bash
ls /root/
exit
-
Save the container as an image
docker commit -a '你的名字' -m '代码描述' test image_test
- -a: author
- -m: submit description information
- test: container name
- image_test: the name of the saved image
-
Save the image as a compressed package [this step can directly send the compressed package to another machine without using the docker hub]
docker save -o test_tar.tar image_test
- test_tar.tar: compressed package name
- image_test: image name
Read the image [If you use a compressed package, it is the 9th step above to see here]
-
Copy the packaged image compression package to the host machine.
-
cd to the compressed package directory, execute:
docker load -i test_tar.tar
-
Create a container named create_test with the image_test image:
docker run --name create_test -idt image_test
-
If you need to map the files in the container with the files outside the container, use the following command to create the container:
docker run --name create_test -v /home/path:/root/ -idt image_test
-v host path container path: This command can map the host path to the container path when creating the container. This allows direct access to host folders within the container. -
into the container:
docker exec -it create_test /bin/bash
upload mirror
-
Login to Docker Hub:
After the user completes the registration on Docker Hub, create a repository.
Then log in on the command line
docker login -u <用户名>
Success display: Login Succeeded
quit:
docker logout
-
Tag the local image
docker tag image name and tag
docker tag local-image:tagname new-repo:tagname
Attach the command to delete the mirror:
docker rmi <image>
-
upload mirror
Users can use the docker push command to upload the image created by themselves to the warehouse for sharing.
docker push new-repo:tagname
This step may appear [denied: requested access to the resource is denied] this problem
Possible solutions are: 1. Login again 2. Make sure you have created a repository in docker hub, and then the tag should be the same as the name of the created repository. You can refer to the tips given on the official website of docker hub: 3. If the network is not good, try
again How many times, just in case the internet is ready