| Command | Description |
|---|---|
curl localhost | Pings the application. |
docker build | Builds an image from a Dockerfile. |
docker build . -t | Builds the image and tags the image id. |
docker CLI | Start the Docker command line interface. |
docker container rm | Removes a container. |
docker images | Lists the images. |
docker ps | Lists the containers. |
docker ps -a | Lists the containers that ran and exited successfully. |
docker pull | Pulls the latest image or repository from a registry. |
docker push | Pushes an image or a repository to a registry. |
docker run | Runs a command in a new container. |
docker run -p | Runs the container by publishing the ports. |
docker stop | Stops one or more running containers. |
docker stop $(docker ps -q) | Stops all running containers. |
docker tag | Creates a tag for a target image that refers to a source image. |
docker --version | Displays the version of the Docker CLI. |
exit | Closes the terminal session. |
export MY_NAMESPACE | Exports a namespace as an environment variable. |
git clone | Clones the git repository that contains the artifacts needed. |
ibmcloud cr images | Lists images in the IBM Cloud Container Registry. |
ibmcloud cr login | Logs your local Docker daemon into IBM Cloud Container Registry. |
ibmcloud cr namespaces | Views the namespaces you have access to. |
ibmcloud cr region-set | Ensures that you are targeting the region appropriate to your cloud account. |
ibmcloud target | Provides information about the account you’re targeting. |
ibmcloud version | Displays the version of the IBM Cloud CLI. |
ls | Lists the contents of this directory to see the artifacts. |
Steps to create and run containers
-
Create a Dockerfile. A Dockerfile is a text file that contains instructions needed to create an image. It’s created using any editor, either from the console/terminal. It has a few instructions in it:
FROM— defines the base imageRUN— executes arbitrary commandsCMD— defines default commands for container execution
-
Use the Dockerfile to create a container image. An image is simply a template for creating a container — it’s read-only, and a writable layer is added when an image is run as a container.
Create a container image using the
docker buildcommand, along with the tag, repository, version, and current directory:Terminal window docker build -t my-app:v1 .To verify the creation of the image, run
docker images. -
Use the container image to create a running container — create it with the
runcommand along with the container image name and tag:Terminal window docker run my-app:v1To verify the details of the container created, run
docker ps -a.
Most used commands
docker image lsordocker images— lists all imagesdocker image rm <image>ordocker rmi— removes an imagedocker image pull <image>ordocker pull— pulls an image from a Docker registrydocker container ls -aordocker ps -a— lists all containersdocker container run <image>ordocker run— runs a container from an imagedocker container rm <container>ordocker rm— removes a containerdocker container stop <container>ordocker stop— stops a containerdocker container exec <container>ordocker exec— executes a command inside the containerdocker system prune— clears almost everything