Communication between Docker containers?
- Mq of container connection host
- A rabbitmq container has been created on the Linux host, and a service container xxx has been created. How does this xxx connect to the rabbitmq container? Because it's all on a Linux, it doesn't seem to work for me to fill in the localhost + port in the xxx service container. Change localhost to the intranet ip, such as (192.168.31.100), but it doesn’t work if it’s the intranet IP. Net IP will change
Q: How to collect Docker container logs?
A:
Q: By docker-compose
of env_file
option is to copy .env
file into the container, or simply set the environment variable?
A: Just simply set the environment variables, and will not .env
file in the host machine to the container, but just .env
to ask the container's environment variables.
You can use the code below to test it yourself 👇
main.py
import os # print(os.environ) print(os.environ['HOST'], type(os.environ['HOST'])) print(os.environ['PORT'], type(os.environ['PORT'])) print(os.getcwd()) print(os.listdir())
Build mirror
sudo docker build -t "testing/docker_log" .
Dockerfile
FROM python:3.9.9-slim ENV PYTHONUNBUFFERED 1 RUN mkdir /code WORKDIR /code COPY main.py /code/
Run container
docker-compose up
docker-compose.yaml
version: "3" services: docker_log_service: container_name: docker_log_service image: testing/docker_log network_mode: "host" env_file: - .env command: python main.py
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。