docker
docker
docker --version
What is the name of the container created using the ubuntu image?
docker ps -a --filter "ancestor=ubuntu" --format "{{.Names}}"
What is the ID of the container that uses the alpine image and is not running?
docker ps -a --filter "ancestor=alpine" --filter "status=exited" --format "{{.ID}}"
What is the status of the container that uses the alpine image
docker ps -a --filter "ancestor=alpine" --format "{{.Status}}"
------------------------------------------
How many ports are published on this container
docker port silly_sammet
Which of the below ports are published on Host
80/tcp -> 0.0.0.0:8080
443/tcp -> 0.0.0.0:8443
Port 80 in the container is mapped to port 8080 on the host.
Port 443 in the container is mapped to port 8443 on the host.
Run an instance of kodekloud/simple-webapp with a tag blue and map port 8080 on the
container to 38282 on the host.
docker run -d -p 38282:8080 kodekloud/simple-webapp:blue
---------------------------------
How many images
docker images
We just pulled a new image. What is the tag on the newly pulled NGINX image?
docker images | grep nginx
We just downloaded the code of an application. What is the base image used in the
Dockerfile?
Inspect the Dockerfile in the webapp-color directory.
cd webapp-color
cat Dockerfile
When a container is created using the image built with this Dockerfile, what is the
command used to RUN the application inside it.
Inspect the Dockerfile in the webapp-color directory.
python app.py
Build a docker image using the Dockerfile and name it webapp-color. No tag to be
specified.
cd webapp-color
docker build -t webapp-color .
Run an instance of the image webapp-color and publish port 8080 on the container to
8282 on the host.
docker run -d -p 8282:8080 --name webapp-color-container webapp-color
docker run: Runs a new container.
-d: Runs the container in detached mode (in the background).
-p 8282:8080: Maps port 8282 on the host to port 8080 on the container.
--name webapp-color-container: Names the container as webapp-color-container.
webapp-color: Specifies the image to use for the container.
Run a container named blue-app using image kodekloud/simple-webapp and set the
environment variable APP_COLOR to blue. Make the application available on port
38282 on the host. The application listens on port 8080.
Deploy a mysql database using the mysql image and name it mysql-db.
Set the database password to use db_pass123. Lookup the mysql image on Docker Hub
and identify the correct environment variable to use for setting the root password.
docker pull mysql
docker run -d --name mysql-db -e MYSQL_ROOT_PASSWORD=db_pass123 mysql
-----------------------------------------------------------------------------------
----
What is the command run at startup when the ubuntu image is run?
docker inspect ubuntu | grep -i cmd
Run an instance of the ubuntu image to run the sleep 1000 command at startup.
Run it in detached mode.
docker run -d ubuntu sleep 1000
----------------------------------------------------------------------------------
create a simple container called redis using image redis:alpine
docker run -d --name redis redis:alpine
Next, create a simple container called clickcounter with the image kodekloud/click-
counter, link it to the redis container that we created in the previous task and
then expose it on the host port 8085
The clickcounter app run on port 5000.if you are unsure, check the hints section
for the exact commands.
cd /root/clickcounter
nano docker-compose.yml
version: '3.8'
services:
redis:
image: redis:alpine
clickcounter:
image: kodekloud/click-counter
ports:
- "8085:5000"
depends_on:
- redis
docker-compose up -d
-----------------------------------------------------------------------------------
-----------
Let practice deploying a registry server on our own.
Run a registry server with name equals to my-registry using registry:2 image with
host port set to 5000, and restart policy set to always.
Note: Registry server is exposed on port 5000 in the image.
Here we are hosting our own registry using the open source Docker Registry.
Now its time to push some images to our registry server. Let's push two images for
now .i.e. nginx:latest and httpd:latest.
Note: Don't forget to pull them first.
To check the list of images pushed , use curl -X GET localhost:5000/v2/_catalog
Now we can pull images from our registry-server as well. Use docker pull [server-
addr/image-name] to pull the images that we pushed earlier.
-----------------------------------------------------------------------------------
-
Explore the current setup and identify the number of networks that exist on this
system.
docker network ls
We just ran a container named alpine-1. Identify the network it is attached to.
docker inspect alpine-1 --format '{{json .NetworkSettings.Networks}}'
Run a container named alpine-2 using the alpine image and attach it to the none
network.
docker run --name alpine-2 --network none -d alpine sleep 1000
Create a new network named wp-mysql-network using the bridge driver. Allocate
subnet 182.18.0.0/24. Configure Gateway 182.18.0.1
docker network create --driver bridge --subnet 182.18.0.0/24 --gateway 182.18.0.1
wp-mysql-network
Deploy a mysql database using the mysql:5.6 image and name it mysql-db. Attach it
to the newly created network wp-mysql-network
Set the database password to use db_pass123. The environment variable to set is
MYSQL_ROOT_PASSWORD.