30 lines
639 B
Markdown
30 lines
639 B
Markdown
---
|
||
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'`
|
||
``` |