Build, Push, and Pull an Image with dch-photon
After you have loaded the vSphere Integrated Containers Registry certificate into a dch-photon
container VM, you can test the dch-photon
Docker host by building an image and pushing it to vSphere Integrated Containers Registry. Then, you can pull the image into a virtual container host (VCH) to deploy it.
Prerequisites
- You performed one of the procedures in either Add the Registry Certificate to a Custom Image or Manually Add the Registry Certificate to a
dch-photon
VM to create an instance of thedch-photon
Docker Engine, namedbuild-slave
.- The
build-slave
container VM includes the CA certificate of your vSphere Integrated Containers Registry instance. - The
build-slave
container VM is exposed on port 12375 of the VCH.
- The
- For simplicity, this example uses a VCH that was deployed with the
--no-tlsverify
option. If your VCH implements TLS verification of clients, you must import the VCH certificates into your Docker client and adapt the Docker commands accordingly. For information about how to connect a Docker client to a VCH that uses full TLS authentication, see Connecting to the VCH in Configure the Docker Client for Use with vSphere Integrated Containers. - This procedure assumes that the VCH uses the same network for the client and public networks. If a VCH is deployed using separate client and public networks, the VCH endpoint is exposed on the client network. When you deploy a
dch-photon
Docker Engine on the VCH, it is exposed on the public network and the commands in the procedure fail.
vSphere Integrated Containers 1.4.x supports dch-photon
version 1.13.
Procedure
Run
docker info
to test that the Docker host running in thedch-photon
container VM has started correctly.By specifying port 12375 you direct the Docker client to the
dch-photon
Docker Engine that is running in the VCH, rather than to the VCH itself.docker -H vch_address:12375 info
Test that you can authenticate with the registry from the
dch-photon
container VM.You should not need to log in if your client is already authenticated with the registry, but the
login
command is included here for clarity. You specify port 12375 to run thelogin
command on thedch-photon
Docker Engine, rather than on the VCH.docker -H vch_address:12375 login registry_address
Test that you can pull images from the registry into the
dch-photon
container VM.Specify port 12375 to run the
pull
command on thedch-photon
Docker Engine.docker -H vch_address:12375 pull registry_address/default-project/dch-photon:1.13
Remove the test image from the
dch-photon
Docker Engine.Specify port 12375 to run the
rmi
command on thedch-photon
Docker Engine.docker -H vch_address:12375 rmi registry_address/default-project/dch-photon:1.13
Create a simple
Dockerfile
and save it in the current directory.Copy the following text into
Dockerfile
:FROM debian:latest RUN apt-get update -y && apt-get install -y fortune-mod fortunes ENTRYPOINT ["/usr/games/fortune", "-s"]
Build an image named
test-container
from theDockerfile
, and tag it with the path to a project in vSphere Integrated Containers Registry.Specify port 12375 to run the
build
command on thedch-photon
Docker Engine.docker -H vch_address:12375 build -t registry_address/default-project/test-container .
Push the image from the
dch-photon
Docker host to the registry.Specify port 12375 to run the
push
command on thedch-photon
Docker Engine.docker -H vch_address:12375 push registry_address/default-project/test-container
Pull the image from the registry into the VCH.
Specify port 2376 to run the
pull
command on the VCH.docker -H vch_address:2376 --tls pull registry_address/default-project/test-container
Instantiate a container from the
test-container
image on the VCH.Specify port 2376 to run the test container on the VCH.
docker -H vch_address:2376 --tls run --name test-container registry_address/default-project/test-container
List the containers that are running and stopped in the VCH.
Specify port 2376 to run the
ps -a
command on the VCH.docker -H vch_address:2376 --tls ps -a
(Optional) Log in to vSphere Integrated Containers Management Portal.
You should see the
test-container
image in the list of repositories fordefault-project
and thetest-container
container VM in the list of containers.
Result
You built a test-container
image in a dch-photon
Docker Engine and pushed it from the dch-photon
instance to vSphere Integrated Containers Registry. You pulled the test-container
image from the registry into a VCH and ran it. The resulting test-container
container VM appears in the list of containers that have run in the VCH.
NOTE: Each dch-photon
Docker Engine that you run creates an anonymous volume in the default
volume store. This anonymous volume is not deleted when you delete a dch-photon
container VM. When you delete dch-photon
container VMs, you must manually remove the anonymous volume from the volume store.