Containers are completely isolated environments. They can have their own separate processes, network, mounts except they all share the OS kernel.
A container is alive only as long as the process inside it is running. As soon as the process is complete, container exits.
A Docker image is a read-only template that contains a set of instructions for creating a container that can run on the Docker platform.
It provides a convenient way to package up applications and pre-configured server environments, which you can use for your own private use or share publicly with other Docker users.
docker run command is used to run a container from an image. For example,
docker run nginx will download the
ngnix application if not found on the host system and run it. The docker image is pulled down only for the first time and the same image is reused when executing the subsequent command.
docker ps command will list all running containers and some basic information about them.
docker ps -a command lists all running containers as well as previously stopped or exited containers.
To stop a container you either need to provide a container name or container ID.
If you don't want to remove a container because you think it is consuming space:
docker rm container_name
docker images shows the list of all images.
docker rmi image_id removes an image that you no longer need.
docker run nginx pulls the nginx image and runs it.
docker pull nginx only pulls the nginx image and stores it on the host but doesn't run it.
docker run kodekloud/simple-webapp runs the container in the attached mode. So you can't essentially do anything until you stop the application.
docker run -d kodekloud/simple-webapp runs the container in the detached mode. So you can do other things while this application is running in the background. You can check the
docker ps to see the running containers.
[email protected]:~$ docker container ls -aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES1fd049cdd7c3 alpine "/bin/sh" 12 hours ago Up 2 hours a-container[email protected]:~$ docker rename a-container web01[email protected]:~$ docker container ls -aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES1fd049cdd7c3 alpine "/bin/sh" 12 hours ago Up 2 hours web01
If you don't have a docker monitoring solution in place, you can use
docker stats or
docker stats <container_name>.
Provides with lots of output. You can grep out only the parts required.
sudo docker run -dp 4000:80 tutum/hello-world
You have to write a Dockerfile with Ubuntu 16.04 as a base image. The image should have following packages present:
Finally, when running a container from the docker image, it should launch with
A README file with instructions on how to build and run the image
FROM ubuntu:16.04RUN apt-get update && \apt-get install -y telnet curl ffmpeg && \apt-get clean
## Instructions to build the docker filemdkir image1cd image1docker build .# Run the docker file in interactive modedocker run -it --name <custom-container-name> <image-id> bash