Files
markdown/blog/1.技术栈/993.Docker 里配置hosts.md
2025-08-08 10:01:03 +08:00

30 lines
639 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: Docker 里配置hosts
description: 在Docker里配置hosts
date: 2025-06-24
img: https://lijue-me.oss-cn-chengdu.aliyuncs.com/20250621163604646.png
navigation:
icon: simple-icons:docker
---
# 一启动容器时加上“—add-host”参数
```
docker run
--add-host='lijue.me:127.0.0.1'
--add-host='www.lijue.me:192.168.1.1'
--name hello-docker
-it reg.lijue.me/public/hello-docker:latest
```
# 二通过docker-compose配置extra_hosts属性
```
1. `version: '3'`
2. `services:`
3. `web:`
4. `image: hello-docker:latest`
5. `extra_hosts:`
6. `- 'www.lijue.me:192.168.1.1'`
7. `- 'lijue.me:127.0.0.1'`
```