Docker
2025年9月5日大约 2 分钟
注意
Docker 在创建新网络时,会从一组默认的私有网段池里“挑”一个未用的范围(172.17.0.0/16 开始,依次递增)。
告诉 Docker 不要用 172.18.0.0/16,换成别的网段
networks:
redis_net:
driver: bridge
ipam:
config:
- subnet: 172.30.0.0/16
gateway: 172.30.0.1
出现这种问题可以使用 ip route show 查看ip路由
排查
docker run -it --entrypoint /bin/sh docker-image
Docker compose
environment variables
Dockerfile
DockerCompose
Composefile
- remove none image
docker image prune
- Docker 的缓存机制
COPY requirements.txt .
RUN pip install -r requirements.txt
## RUN pip install "..." 替换这个 可以使用缓存
RUN pip install "..." 就像每次都在写一篇新文章,哪怕内容一样,文件名都不同,系统不认缓存。
COPY requirements.txt && pip install -r 就像你上传一份清单,只有清单变了才重新下载。
entrypoint and cmd
Great question! The difference between `ENTRYPOINT` and `CMD` in Docker is subtle but important, especially for how the container runs and how you can override commands.
---
### Why use `ENTRYPOINT` vs `CMD`?
#### 1. `ENTRYPOINT`
* Defines the **main executable** that always runs when the container starts.
* You can **append arguments** to the `docker run` command, and those will be passed as parameters to the entrypoint.
* Useful when you want the container to behave like a specific program or tool, but still accept flexible arguments.
Example:
```Dockerfile
ENTRYPOINT ["python", "bin/datax.py"]
If you run:
docker run datax-image /opt/datax/job/job.json
It executes:
python bin/datax.py /opt/datax/job/job.json
2. CMD
- Provides default arguments to the container’s command.
- Can be overridden entirely by passing a new command in
docker run
. - If you use
CMD
alone withoutENTRYPOINT
, the entire command can be replaced.
Example:
CMD ["python", "bin/datax.py"]
If you run:
docker run datax-image /opt/datax/job/job.json
Docker will ignore the CMD and try to run /opt/datax/job/job.json
as a command, which will fail.
Which one to use for DataX?
- Using
ENTRYPOINT
forpython bin/datax.py
makes the container act like the DataX executable. - You then just pass the job JSON file as an argument when running the container.
- If you used
CMD
, running the container with extra arguments would replace the entire command, which is usually not what you want.
TL;DR
- Use
ENTRYPOINT
when you want a fixed executable and flexible arguments. - Use
CMD
when you want default commands/args but allow full override.
Want me to help you adjust your Dockerfile to work perfectly with your workflow?