A container is launched by running an image.
An image is an executable package that includes everything needed to run an application – the code, a runtime, libraries, environment variables, and configuration files.
1
2
3
## Display Docker version and info
docker version
docker info
Dockerfile
Dockerfile
defines what goes on in the environment inside your container.
Docker can build images automatically by reading the instructions from a Dockerfile
.
1
2
3
4
5
6
FROM python:3.7.4-alpine3.10
WORKDIR /app
COPY . /app
RUN pip install ipython
RUN pip install --trusted-host pypi.python.org -r requirements.txt
CMD ["ipython"]
1
docker build app .
1
2
# Copy file from local machine to docker
docker run -it -v `pwd`:/files alpine
The docker build command builds an image from a Dockerfile
and a context.
Note that each instruction is run independently, and causes a new image to be created - so RUN cd /tmp
will not have any effect on the next instructions.
The instruction is not case-sensitive. However, convention is for them to be UPPERCASE to distinguish them from arguments more easily.
A Dockerfile
must start with a FROM
instruction.
The FROM
instruction specifies the Base Image
from which you are building.
Difference between Docker Create, Start and Run
Create
adds a writeable container on top of your image and sets it up for running whatever command you specified in your CMD. The container ID is reported back but it’s not started.
Start
will start any stopped containers. This includes freshly created containers.
Run
is a combination of create and start. It creates the container and starts it.
CLI
1
2
3
4
5
6
docker run
docker ps
docker images
docker start
docker stop
docker exec
Register
1
docker run -d -p 5000:5000 --restart=always --name registry registry:2
1
2
3
docker pull ubuntu:16.04
docker tag ubuntu:16.04 localhost:5000/my-ubuntu
docker push localhost:5000/my-ubuntu
1
2
docker image remove ubuntu:16.04
docker image remove localhost:5000/my-ubuntu
1
docker pull localhost:5000/my-ubuntu
HTTP
/etc/docker/daemon.json
1
2
3
{
"insecure-registries" : ["http://myregistrydomain.com:5000"]
}
Docker CLI will try using
HTTPS
first!
Tips
Run without exiting
1
docker run -dit ubuntu