Docker uses "two" under Windows

Source: Internet
Author: User
Tags docker ps docker hub jupyter docker run

can refer to the study address: Geek College Docker tutorial, also good, can refer to

1.Dockerhub Download Image

: Dockerhub Address

There are two ways to get a new image

    • Download the compiled image directly from Dockerhub (the compilation process is done in the cloud of the Docker hub) (see 3.1)
    • Download Docekrfile file, build in this machine
Pull pre-built image directly on Dockerhub

Enter the following command in the terminal:

sudo Docker pull tingtinglu/docker

Note:
①tingtinglu/docker is the name of pre-built image on Dockerhub.
② How do I get the name of pre-built image? Need to search for the image you need on Dockerhub

Download Dockerfile file, build in this machine

For details, see Docker's official documentation: Build your own image, introducing how to use Dockerfile to compile your own image

(1) Get Dockerfile (that is, download a file with the name Dockerfile, the content is some of the commands for constructing Docker)

(2) Use Terminal's CD command to enter the folder where the Dockerfile is located

(3) Under the folder where the file named "Dockerfile" is located (that is, terminal CD to that folder), execute the following command

-t ImageName .

Note 1:imagename is the name of the image generated using dockerfile (self-setting)
Note 2: Do not forget the point behind the imagename "."

Make some changes to an existing image using the Dockerfile file

Sometimes, you get an image, but you need to make a new change to the image, for example, to add a new path workspace under the OPT path of Docker, which can be done through Dockerfile, as follows:

① Create a new dockerfile, add the following:

mkdir /opt/workspace

② uses terminal to enter the path of the Dockerfile, and then built the Dockerfile, executing the following command:

-t ImageNameOld

Be sure to note that the imagenameold here is the name of the image you want to add the change to

2. Create a container with a downloaded image

On the command line, enter a command similar to the following:

-it --rm -p 8888:8888 -v `pwd`/workspace:/opt/workspace -v `pwd`/data:/root/data tingtinglu/deepdock

The following is an analysis of the command

(1) -p 8888:8888
Associating the 8888 interface of Jupyter in Docker with the 8888 interface of the native

(2) -v `pwd`/workspace:/opt/workspace
Map the Workspaace folder under the current path (the ' pwd ') to the workspace folder under the OPT path in Docker, so that the opt/workspace under Docker points to the ' PWD '/workspace folder on the machine;

There is another way to do this: use Terminel to enter the workspace path to this machine, and then:-v ¨$(pwd):/opt/workspace¨

The specific illustrations are as follows:

At this point, after re-entering Docker, the contents of Docker's/opt/workspace/become the contents of native workspace;
It can be thought that regardless of the original Docker/opt/workspace content, now the workspace content is covered by the workspace of the machine, that is, Docker Opt/workspace is no longer point to Daocker opt/ Workspace, but only the workspace folder that points to this machine

(3) Sometimes, Docker may not be able to access the Internet, then, you can join --net=host , that is, the complete command as follows:

-it --rm -p 8888:8888 --net=host -v `pwd`/workspace:/opt/workspace -v `pwd`/data:/root/data tingtinglu/deepdock

(4) If it is a Windows system, then the folder mapping requires an absolute path
The following command is required:

-it --rm -p 8888:8888 --net=host -v `pwd`/workspace:/root/opt/workspace -v `pwd`/data:/root/data tingtinglu/deepdock

And, Windows currently only supports C drive! Be sure to pay attention!

Note: The docker instruction pattern is: indicator + parameters, i.e. [sudo] docker [flags] [command] [arguments]

eg.: Docker run-i-T Ubuntu/bin/bash

3. View the local Docker images
sudo docker images

Will get all the images information on this machine.

    • The first column is the name of the Docker image
    • The second column is the tag of the image (the same image sometimes needs to be changed several times, in order to distinguish between different versions of the image, the image is given a tag)
    • The third column is the ID of the Docker image
    • The fourth column is the creation time of the DOCEKR image
    • The fifth column is the size of the Docker image
4. View the running container
sudo docker ps

The information displayed is as follows:

Container Id IMAGE Command Created Status Ports names
ID of the container The name of the image that generated the container The time that the container was generated The state of the container ContainerName (Auto Assign)
5. Enter the running Docker in bash mode
sudo docker exec -it containerName bash

Legend:

(1) ls
List the folders under Docker container

As you can see, in the Container ls folder, there are two folders, respectively, Caffe and workspace

(2) cd..
Return to the current folder upper level folder of opt
and lists all the files ls under that folder

You can see all the folders for the container

(3) It should be noted here:

    • Because of the preceding command:
`pwd`/workspace:/opt/workspace 

Mapping the workspace folder under the current path ' pwd ' (' pwd ' to the path where the Docker container was generated) to workspace under the OPT folder in Docker container

    • Because of the preceding command:
-v `pwd`/data:/root/data

Causes the Data folder under the current path ' pwd ' of the local computer to be mapped to data under the root folder in the Docker container

6. Save a container as an image

If you make some changes to Docker, and the changes are not software that installs Jupyter, but only installs some packages, saving the new image requires only:

sudo docker commit containerID newImageName

Containerid is the name of the new image for the id,newimagename of the container to be saved
For example: Ting/caffe:version1 such a name, where Version1 is the flag of the new container, which can be used to identify the version information of the new image

7. Update the image from the container you have created, and submit the image
    • Make the appropriate changes in the container
      Example: Apt-get install wget
    • Save the container as a new mirror
      sudo docker commit Containerid Newimagename:tag
8. Delete/Stop commands
    • Removing mirrors from the host
      sudo docker rmi 镜像名称

    • Stop a running container
      sudo docker stop containerName

    • Removing a container
      sudo docker rm containerID

Note: When you enter an ID, you do not have to enter the full ID, and the first few characters are usually used to identify

Various Error Records Error response from daemon:conflict:unable to delete 40787553f761 (must being forced)-image is being used by stopped Container 8a1faaf9d24b

    • The problem is due to the fact that container (id:8a1faaf9d24b) generated by image-40787553f761 still exists
    • However, with Sudo Docker PS, it is not possible to display container-8a1faaf9d24b because the container-8a1faaf9d24b is not running, but it still exists, so it must be removed
    • Workaround: Use docker rm <containerid> that 8a1faaf9d24b to remove the container

Cannot connect to the Docker daemon. Is the Docker daemon running on
This host?

    • Need to use sudo
Other precautions

1. Recently found that many of their native mirrors are none, and the reason for the query discovery may be:

Duplicate pull the mirror of the same tag, and, when pull the new mirror (with the old image of the machine has the same tag), the old mirror is already occupied by the container, then after the pull new mirror, the old image that was occupied before will become none

2. In the native writing Dockerfile, the dockerfile used the native mirror a (from a), using the Dockerfile build mirror B, then Mirror B is called mirror a child

Docker uses "two" under Windows

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.