picture

Many friends have read the previous series of Docker The article looks confused , This sum Python What does it matter ?

Docker It can be used to reduce the tedious steps of building our environment , We can put something like selenium And so on Docker The container is deployed , Use the remote... Directly in the code selenium, Easy and convenient .

Use Docker In container Python Environment for development

Environmental preparation : Tencent cloud CentOS 7 + Docker

modify Docker To configure

Easy version :

edit Docker Related configuration files :

vi /etc/docker/daemon.json 

Insert the following configuration :

Note that this is the standard json Format , Format error Docker It won't restart

{
  "hosts": ["tcp://0.0.0.0:2375","unix:///var/run/docker.sock"]
}

heavy load Docker To configure :systemctl daemon-reload

restart Docker:systemctl restart docker

Complex version :
This version is used to use the above configuration to modify the situation still unable to connect , This was the case with the first configuration of salted fish , Salted fish found the answer in the notes section of a lesson net .

Post the original address here :

 Reference link :https://www.imooc.com/article/details/id/28426

The specific operation is as follows :
Edit the file below :

vi /lib/systemd/system/docker.service

Modify and save the corresponding configuration item of the file :

 take 
ExecStart=/usr/bin/dockerd
Change it to
ExecStart=/usr/bin/dockerd -H unix:///var/run/docker.sock -H tcp://0.0.0.0:2375
To configure Pycharm

Start by opening Pycharm in Docker Display items for :

 picture

modify Docker To configure :

 picture

Fill in the corresponding space in the figure below Docker To configure :

 picture

Notice the format here : tcp://host:ports

After the configuration is completed, you will be prompted that the connection is successful .

Configure remote Docker As a mirror of Pycharm Interpreter

Click on configuration , Click Add configuration :image.png Select... From the new items Docker, Your connection will be automatically loaded here Docker The service contains Python All the images of :image.png Automatic upload of configuration code

You think it's over up there ? The interpreter is configured , But your code is still local , So the configuration code needs to be uploaded to the cloud server automatically .

First, find the corresponding option , If it has not been configured before, the options here are gray , Configuration required , Click on configuration :

 picture

Click on the plus sign , Fill in the corresponding configuration , You can test if it's available after filling in :

 picture

If you can't use , It is recommended to log in to the console , Configure the relevant security group configuration .

Switch to the next one mapping tab , Configure the relevant path and the path to upload to the server according to the figure below :

 picture

After that , Return to the first figure in this section , There is an automatic upload option to bring it up , After that, when your file changes, it will be automatically uploaded to the path specified by the server .

Come here , It's naive of you to think it's over .

Solve the problem of error report after the code is uploaded automatically

When you upload the code , Error reported after operation “ Unable to find the corresponding folder / file ”, This is because our code is only uploaded to the server at this time , But our Python The interpreter runs in a container , And our container search code is the data volume we are looking for , So at this time, we need to do a simple address mapping in the configuration .

Let's take a look at the schematic diagram involved in the above paragraph :

 picture

And then we start to configure , Global address mapping :image.png stay Docke Edit configuration in component , add to path mapping
effect : When we configure the cloud service path, we will automatically map our local path

Set up Python default mapping For the corresponding path :

Pay attention here : there container path It refers to the path in the container , Combined with the above schematic diagram , The whole mapping process is The local path -> Cloud server path -> Container path image.png The above is the whole content of this article , If you don't understand the principle , Salted fish suggest that we can review the previous information about Data volume Part of , If you still don't understand, you can ignore the principle , Just follow the plan and finish the job , Of course, you are welcome to leave a message ~ ~

 picture  picture

Saltfish Science Python

Focus on Python Commercial reptiles 、Python Salted fish of Data Science