Skip to main content

17 posts tagged with "docker"

View All Tags

Configuring /etc/hosts/in Kubernetes Depolyment/Pod

· One min read

Example of Pod:

apiVersion: v1
kind: Pod
metadata:
name: hostaliases-pod
spec:
restartPolicy: Never
hostAliases:
- ip: "127.0.0.1"
hostnames:
- "foo.local"
- "bar.local"
- ip: "10.1.2.3"
hostnames:
- "foo.remote"
- "bar.remote"
containers:
- name: cat-hosts
image: busybox
command:
- cat
args:
- "/etc/hosts"

Example of Deployment

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: hostaliases-deployment
spec:
template:
spec:
hostAliases:
- ip: "127.0.0.1"
hostnames:
- "foo.local"
- "bar.local"
- ip: "10.1.2.3"
hostnames:
- "foo.remote"
- "bar.remote"
containers:
- name: a-aspnetcore-app
image: aspnetcore-app:v1.0.0
env:
- name: ASPNETCORE_ENVIRONMENT
value: Development
ports:
- containerPort: 80
imagePullSecrets:
- name: docker-secret

See the result in Kubernetes container

# cat /etc/hosts
# Kubernetes-managed hosts file.
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
fe00::0 ip6-mcastprefix
fe00::1 ip6-allnodes
fe00::2 ip6-allrouters
192.168.240.234 hostaliases-deployment-65d5c48f7c-pqqvn

# Entries added by HostAliases.
127.0.0.1 foo.local bar.local
10.1.2.3 foo.remote bar.remote

reference: add-entries-to-pod-etc-hosts-with-host-aliases

Docker Windows容 器中的时间问题

· 2 min read

场景 #1:

主机 OS 版本: Windows 10 1803 容器 OS 版本: Windows Server Core 1803

容器以默认的 hyperv 模式启动, 空器中的时间是一个莫名其妙的未来时间,比主机的时间提前 10 多个小时: 主机的时间是 2018-8-15 17:XX:XX, 容器中的时间是 2018-8-16 07:XX:XX 又一次代码修改重新构建了容器的镜像,重启了容器,容器的时间与主机的时间同步了

测试: 1. 当前实际时间为 2018-8-16 16:XX:XX, 关掉主机中的自动设置时间, 修改主机的时间为 2018-5-16 16:XX:XX,容器中的时间不变,重启容器后容器中的时间变成 2018-8-16 09:XX:XX 2. 打开主机中自动设置时间,主机时间变回,2018-8-16 16:07:XX, 容器的时间也跟着同步成了 2018-8-16 16:07:XX 3. 再次关掉主机中的自动设置时间,把主机时间改为 2018-8-19 16:07:XX, 容器的时间马上跟着变成了 2018-8-19 16:07:XX 4. 再次打开主机中的自动设置时间,主机时间变回 2018-8-16 16:09:XX, 容器时间还维持在 2018-8-19 16:XX:XX 5. 再次重启容器,容器的时间又与主机同步了

结论: 当容器中的时间比主机的时间晚时,与立即与主机时间同步,反之则不会同步。莫名其妙, 参见 bug: https://github.com/moby/moby/issues/37283

场景 #2:

主机 OS 版本: Windows Server 2016 14393.1358 容器 OS 版本: Windows Server Core 10.0.14393.2363

容器以 process 模式启动, docker run ... --isolation process... 不管主机时间如果变化,容器中的时间都与主机时间同步

hyperv 或 process 兼容列表见: https://docs.microsoft.com/en-us/virtualization/windowscontainers/deploy-containers/version-compatibility

ClustrMaps