k8s记录-Docker配置主机

docker容器配置hosts

可以通过下面两种方法把hosts配置到docker容器上

一、启动容器的时候加上“--add-host”把hosts配置上

# docker run --add-host=www.baidu.com:127.0.0.1 xxx -it /bin/bash

上面的容器启动之后,会把 “www.baidu.com  127.0.0.1” 这个配置写到容器的 /etc/hosts中

进入到容器中验证下

# docker ps -a
# docker exec xxxx -it /bin/bash    #xxx是上面执行后的容器id,CONTAINER ID
# cat /etc/hosts

二、通过 docker-compose.yaml 文件启动

通过 extra_hosts 将hosts配置到容器中

复制代码
php72:
  container_name: "php72"
  hostname: "php72"
  image: "xxxx"
  extra_hosts:
    - "www.baidu.com:127.0.0.1"
- "www.google.com:127.0.0.1" volumes: - xxx:xxx
复制代码
 
posted @ 2020-05-19 12:20  信方  阅读(646)  评论(0编辑  收藏  举报