Answer the question
In order to leave comments, you need to log in
How to effectively develop Python applications in Pycharm using Docker?
I use pycharm to develop Django applications.
The standard development process: we take a virtualenv, put everything there, in pycharm we specify this virtual machine as a SDK for the project, everything is great.
Having decided to use docker, I ran into some problems. In particular, I'm interested in the following:
0.1. In various guides, they put nginx into a container, it is not clear why this is done, if the production server will still have its own nginx.
1. If we refuse virtualenv and the whole environment is in our container, then how to specify the path to it in pycharm-e, and to be more precise, how to add containers from the local machine to docker-machine, because in pycharme the environment can only be taken through docker machine.
2. I also haven't found a solution yet - why pdb.set_trace() crashes immediately when triggered, when launched from a container.
3. And in general, I’m interested in how best to organize the directory structure for dockerfiles, compos, sorts, statics, media
Answer the question
In order to leave comments, you need to log in
0. nginx (proxy server) is inserted into the container if the main proxy cannot be specified where you have the static
schema
#### server
балансер(прокси) | {твой контейнер: nginx -> [static_files, dynamic_django]
| {другой контейнер: nginx -> [static_files, dynamic]
....
#### server
/usr/local/bin/python
Well, either I explain very poorly, or the previous speaker could not understand me, or something else, but I found an answer to some of the questions:
which sshd
and if not, then put one, for example. sudo apt-get install openssh-server
--generic-ssh-key
for will help here docker-machine create
, but I didn’t understand this, but through I sudo visudo
allowed my user to do everything without a password by adding the line username ALL=(ALL) NOPASSWD: ALL
├── docker-compose.yml
├── nginx
│ ├── Dockerfile
│ └── sites-enabled
│ └── django_project
├── production.yml
└── web
├── Dockerfile
├── docker_django
│ ├── __init__.py
│ ├── apps
│ │ ├── __init__.py
│ │ └── todo
│ │ ├── __init__.py
│ │ ├── admin.py
│ │ ├── models.py
│ │ ├── templates
│ │ │ ├── _base.html
│ │ │ └── home.html
│ │ ├── tests.py
│ │ ├── urls.py
│ │ └── views.py
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
├── manage.py
├── requirements.txt
└── static
└── main.css
Two options:
1. Use PyCharm's native docker support.
The integration seems to be designed for docker-machine and boot2docker. But if you want to use docker from the host system, then setting up docker-machine and ssh is not necessary. Instead, you can use the stub script from https://youtrack.jetbrains.com/issue/PY-17454#comm... Specify the path to the docker-machine stub in the PyCharm settings.
You need to add the user "docker" with the password "tcuser" to the system. These details are used by the debugger.
sudo useradd --system --create-home --home /var/lib/docker docker
echo 'docker:tcuser' | chpasswd
sudo iptables -A INPUT -i docker0 -j ACCEPT
sudo ip addr add 10.0.2.2/8 dev docker0 \
&& (sudo ip link set dev docker0 down; sudo ip link set dev docker0 up) ||:
# за основу берется проектный image
FROM myproject
# sshd
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
openssh-server \
vim \
&& rm -rf /var/lib/apt/lists/* \
&& mkdir -p -m0755 /var/run/sshd \
&& echo 'root:screencast' | chpasswd \
&& sed -i 's/PermitRootLogin without-password/PermitRootLogin yes/' /etc/ssh/sshd_config \
&& sed '[email protected]\s*required\s*[email protected] optional [email protected]' -i /etc/pam.d/sshd \
&& echo "export VISIBLE=now" >> /etc/profile
# PyCharm хочет исходники в /opt/project
WORKDIR /opt/project
# автоматически активировать virtualenv при логине root
RUN echo "\ncd /opt/project; if [ ! -f env/bin/activate ]; then virtualenv env; fi; . env/bin/activate" >> /root/.bashrc
# ssh, django runserver
EXPOSE 22 8000
CMD ["/usr/sbin/sshd", "-D"]
# docker-compose-dev.yml
# vim: sw=2 ts=2
version: '2'
services:
web:
build: .
links:
- db
volumes:
- ./:/opt/project
- ./data/env:/opt/project/env
ports:
- "127.0.0.1:2222:22"
- "127.0.0.1:8000:8000"
db:
image: mysql
volumes:
- ./data/mysql:/var/lib/mysql
environment:
- MYSQL_ALLOW_EMPTY_PASSWORD=yes
- MYSQL_DATABASE=mydb
ports:
- "3306:3306"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question