Searching for images:

To look for images in the docker repository, we use the below command to look for "debian" images for example:



Pulling an image from the repository:

To pull "debian" from the default repository and run it, we use:



To pull an image from a specific repository, we use the below:



Example:

Pulls and runs the "truecommand" image and publishes the ports. It maps port 80 on the host to port 80 on application running in the container.


Building a docker image:

We build an image locally by running the below command:



Some elements of a "dockerfile":


Builds the base image from a "debian" or "ubuntu" image for example "FROM debian:latest".


Environmental variable built in the image.


RUN executes a command, the output of the command becomes a new layer to be added to the image.


The ADD instruction copies local files or remote URLs, then adds them to the image at the destination path.



Default command that is executed when the container starts, it can be easily overridden using the command line "docker run image command".


Runs the command when the container starts. It can not be overridden like the CMD command.


The COPY instruction copies files from the source into the destination path in the container.


We use this LABEL instruction to add information about an image. 
This information could be viewed using the command : "docker inspect image_name".


Sets the directory where the following instructions will execute.


We could also use the UID of the user. 
The USER instruction sets the user under which all the following instructions will be run.

The "Dockerfile" instructions and the final image:

The output of each of these above instructions builds a layer and all the layers combined constitute a docker image. 



Brando Sabatini and Ikbal C ©. Powered by Blogger.