/root/docker_python directory structure:
.
|-- demo
| `-- main.py
`-- docker-compose.yml
main.py content:
# coding=utf-8
# -*- coding: utf-8 -*-
if __name__ == '__main__':
print("hello world")
docker-compose.yml contents:
version: "3"
services:
docker_python:
image: python:2.7.18
container_name: py_app
working_dir: "/root"
restart: always
volumes:
- "/root/docker_python/demo:/root/demo"
networks:
- py_net
stdin_open: true
tty: true
networks:
py_net:
#driver: bridge
Which stdin_open
is equivalent to run
the command -d
,
which tty
is equivalent to run
the command -i
stdin_open: true
tty: true
Among them, networks can use the created network, assuming xxx is the created network
networks:
xxx:
external: true