运行 使用 GCP 在 kubernetes 上修改了 Dockerfile
running modified Dockerfile on kubernetes with GCP
我在google云平台上有一个Kubernetes v1.8.6集群。
我的桌面是 macbook pro 和 high sierra,kubectl 使用 google-cloud-sdk 安装,docker 使用 homebrew 作为虚拟机安装。
我使用以下 kubernetes 部署 yaml 文件安装了 php docker 映像:
apiVersion: apps/v1beta2 # for versions before 1.8.0 use apps/v1beta1
kind: Deployment
metadata:
name: php-deployment
labels:
app: php
spec:
replicas: 1
selector:
matchLabels:
app: php
template:
metadata:
labels:
app: php
spec:
containers:
- name: php
image: php:7.1.13-apache-jessie
volumeMounts:
- mountPath: /var/www/html
name: httpd-storage
- mountPath: /etc/apache2
name: httpd-conf-storage
- mountPath: /usr/local/etc/php
name: php-storage
ports:
- containerPort: 443
- containerPort: 80
volumes:
- name: httpd-storage
gcePersistentDisk:
fsType: ext4
pdName: httpd-disk
- name: httpd-conf-storage
gcePersistentDisk:
fsType: ext4
pdName: httpd-conf-disk
- name: php-storage
gcePersistentDisk:
fsType: ext4
pdName: php-disk
我用kubectl create -f yaml.file
安装的
它有效..到目前为止一切顺利。
现在我想扩展此映像以在其上安装 CertBot。
所以我创建了以下 Dockerfile
:
FROM php:7.1.13-apache-jessie
RUN bash -c 'echo deb http://ftp.debian.org/debian jessie-backports main >> /etc/apt/sources.list'
RUN apt-get update
RUN apt-get install -y python-certbot-apache -t jessie-backports
我将此文件放在名为 build
的目录中,并使用 docker build -t tuxin-php ./build
.
从 docker 文件构建了一个图像
我不知道 docker 图像放在哪里,因为 docker 是 运行 在 high sierra 的 VM 之外,如果我有本地访问权限,我会有点困惑或需要做 scp,但可能不需要。
有没有办法直接安装我创建的Dockerfile?
我必须创建图像并以某种方式安装它吗?如果是的话怎么办?
我有点困惑,如能提供有关此问题的任何信息,我们将不胜感激。
谢谢
首先,您需要构建 docker 图像。然后您需要将您的图像推送到 docker 注册表中。为什么?这样您的 pod 就可以从该注册表中提取该图像。建立形象是不够的。
现在你应该把那张 docker 图片放在哪里。你可以试试 https://hub.docker.com/.
您可以按照以下步骤操作:
- 在 https://hub.docker.com/
创建一个帐户
- 将您的计算机配置为使用您的 docker 注册表帐户。
使用这些命令
$ docker login
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username: <your docker hub username>
Password: <your docker hub password>
现在您已准备好将 docker 图像推送到注册表中。
在这种情况下,您想要推送名为 tuxin-php
的图像。因此,您需要使用相同的名称 tuxin-php
在 docker 集线器 (https://hub.docker.com/) 中创建一个存储库。 (https://docs.docker.com/docker-hub/repos/)
现在试试这个
$ docker build -t xxxx/tuxin-php ./build
$ docker push xxxx/tuxin-php
Here, xxxx
is your docker username.
当您推送 xxxx/tuxin-php
时,您的图像将以您的用户名存储在 tuxin-php
存储库中。
最后,你必须使用这张图片。
containers:
- name: php
image: xxxx/tuxin-php
您的 pod 将从 docker 中心拉取 xxxx/tuxin-php
。
希望这会有所帮助
我在google云平台上有一个Kubernetes v1.8.6集群。
我的桌面是 macbook pro 和 high sierra,kubectl 使用 google-cloud-sdk 安装,docker 使用 homebrew 作为虚拟机安装。
我使用以下 kubernetes 部署 yaml 文件安装了 php docker 映像:
apiVersion: apps/v1beta2 # for versions before 1.8.0 use apps/v1beta1
kind: Deployment
metadata:
name: php-deployment
labels:
app: php
spec:
replicas: 1
selector:
matchLabels:
app: php
template:
metadata:
labels:
app: php
spec:
containers:
- name: php
image: php:7.1.13-apache-jessie
volumeMounts:
- mountPath: /var/www/html
name: httpd-storage
- mountPath: /etc/apache2
name: httpd-conf-storage
- mountPath: /usr/local/etc/php
name: php-storage
ports:
- containerPort: 443
- containerPort: 80
volumes:
- name: httpd-storage
gcePersistentDisk:
fsType: ext4
pdName: httpd-disk
- name: httpd-conf-storage
gcePersistentDisk:
fsType: ext4
pdName: httpd-conf-disk
- name: php-storage
gcePersistentDisk:
fsType: ext4
pdName: php-disk
我用kubectl create -f yaml.file
它有效..到目前为止一切顺利。
现在我想扩展此映像以在其上安装 CertBot。
所以我创建了以下 Dockerfile
:
FROM php:7.1.13-apache-jessie
RUN bash -c 'echo deb http://ftp.debian.org/debian jessie-backports main >> /etc/apt/sources.list'
RUN apt-get update
RUN apt-get install -y python-certbot-apache -t jessie-backports
我将此文件放在名为 build
的目录中,并使用 docker build -t tuxin-php ./build
.
我不知道 docker 图像放在哪里,因为 docker 是 运行 在 high sierra 的 VM 之外,如果我有本地访问权限,我会有点困惑或需要做 scp,但可能不需要。
有没有办法直接安装我创建的Dockerfile? 我必须创建图像并以某种方式安装它吗?如果是的话怎么办?
我有点困惑,如能提供有关此问题的任何信息,我们将不胜感激。
谢谢
首先,您需要构建 docker 图像。然后您需要将您的图像推送到 docker 注册表中。为什么?这样您的 pod 就可以从该注册表中提取该图像。建立形象是不够的。
现在你应该把那张 docker 图片放在哪里。你可以试试 https://hub.docker.com/.
您可以按照以下步骤操作:
- 在 https://hub.docker.com/ 创建一个帐户
- 将您的计算机配置为使用您的 docker 注册表帐户。
使用这些命令
$ docker login
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username: <your docker hub username>
Password: <your docker hub password>
现在您已准备好将 docker 图像推送到注册表中。
在这种情况下,您想要推送名为 tuxin-php
的图像。因此,您需要使用相同的名称 tuxin-php
在 docker 集线器 (https://hub.docker.com/) 中创建一个存储库。 (https://docs.docker.com/docker-hub/repos/)
现在试试这个
$ docker build -t xxxx/tuxin-php ./build
$ docker push xxxx/tuxin-php
Here,
xxxx
is your docker username.
当您推送 xxxx/tuxin-php
时,您的图像将以您的用户名存储在 tuxin-php
存储库中。
最后,你必须使用这张图片。
containers:
- name: php
image: xxxx/tuxin-php
您的 pod 将从 docker 中心拉取 xxxx/tuxin-php
。
希望这会有所帮助