Docker 101 : Docker basic commands 2
The image will be downloaded from the docker hub if the image does not exist on the host.
Docker pulls images layer per layer, if a layer already exists on the host it does not pull it from the docket hub.
Pulling an image from the docker hub without running it:
Listing the latest created container:
Listing all the containers (running and stopped ):
Stopping a running container:
Remark:
We could use the container name or the container ID.
Listing docker images on the machine:
Or:
Removing an images:
The containers using this image need to be stopped before we can delete it (the image) using the above command.
Executing a command inside a running container:
We could use the container name or the container ID that we can get by running the "docker container ls" command.
Running a container in a detached mode:
Removing a container:
We can't remove a running container, we need to stop it first using the below command:
Then, we can remove it using the below:
Running a container in the background:
Runs a container in the background in a detached mode.
We can bring it back to the "foreground" using the "attach" command as below:
The above command reattaches the container to the standard output.
Running a image in an interactive mode:
- -i: interactive mode.
- -t: attaches the container to the standard output.
Port mapping:
Maps a port on the docker container to a free port on the host:
Maps the host_port on the host to container_port on the container.
We can access the application in the container, using the "ip_of_host:host_port" combination.
Traffic to the "host_port" port will be routed to "container_port" port on the container.
Volume mapping:
We use the below command to map a folder in the host to a folder in the docker container:
When the container exits or crashes, all the data will be safe on the host folder.
All the data will be stored in the host directory.
Getting information about the container:
Reading a container logs:
Comments