...

/

Jenkins Kata 6: Deploying Containers (Step 4–6)

Jenkins Kata 6: Deploying Containers (Step 4–6)

Learn about adding a build pipeline, defining and configuring a Dev, QA, and production environment deployment job, and adding a pipeline view.

Step 4: Define a QA environment deployment job

The following are the steps to define a QA environment deployment job:

  • Return to the Jenkins tab.
  • Click the “Jenkins” icon at the top left.
  • Click “New Item.”
  • Enter “qa-deploy-storelist” in the item name field.
  • Select “Freestyle project.”
  • Click “OK.”
Press + to interact
Job creation for qa-deploy-storelist
Job creation for qa-deploy-storelist
  • Click the “Build Steps” tab.
  • Select “Add build step.”
  • Select “Execute shell.”
  • Enter the following commands:
Press + to interact
docker container rm -f qa-storelist || true
docker container run -d -p 8002:80 --net=storelist-net --ip=172.20.0.15 --name qa-storelist ed-6091404232622080.educative.run/dk/storelist
  • Click “Save”
Press + to interact
Adding commands in the “Command” field
Adding commands in the “Command” field

Commands

Command / Parameter

Description

docker container

This is the Docker parent command for containers.

rm

This removes a container.

-f

This forces the removal of a container even if it's running. If the container is running, it's killed and then removed.

qa-storelist

This is the name of the container to remove.




|| true

The double-pipe character is a “logicial OR.”

If the `qa-storelist` container is not running, the Docker `rm` command will fail. This is expected; however, it would cause the command to return a failure code, causing the job to fail. The OR statement returns true from the command even if the docker `rm` command fails.

This ensures that this command will return a success code, whether the `qa-storelist` container was running or not.

docker container

This is the Docker parent command for containers.

run

This runs a new container.

-d

This runs a disconnected container.

-p

This maps ports from the host to the container.

8002:80

This maps port 8002 on the host to port 80 in the container.

--net=storelist-net

This assigns a user-defined Docker bridge network to the container.

--ip=172.20.0.15

This assigns a static IP to the container within the subnet range defined on the user-defined network.

--name

This assigns a name to the container.

qa-storelist

This is the name assigned to the container.

ed-6091404232622080.educative.run/dk/storelist

This is the URL to the private repository and the name of the image to run.

  • Click “Build Now.”
Press + to interact
Click “Build Now”
Click “Build Now”
  • Click back to “Dashboard.”
  • Select the “dev-deploy-storelist” job.
  • Click “Configure.”
  • Click the “Post-build Actions” tab.
  • Select “Add post-build action.”
  • Select “Build other projects (manual step).”
  • Enter “qa-deploy-storelist” in the “Downstream Project Names” field.
  • Click
...