Creating Images
Commands
Building Images
| Command | Description |
|---|---|
docker build . |
Build an image from the Dockerfile in the current folder |
docker build -f <file> . |
Build an image from |
docker build -t <name> . |
Build an image and tag it with |
docker build -t <name>:<tag> . |
Build an image and tag it with |
docker build --no-cache . |
Build an image without cache |
docker build --target <stage> . |
Build an image up to stage |
docker build --build-arg MYARG=myvalue . |
Build an image with the build argument MYARG |
Managing Images
| Command | Description |
|---|---|
docker tag <image> <name>:<tag> |
Tag an image |
docker tag <image> <registry>/<project>/<name>:<tag> |
Tag an image |
docker image push <name>:<tag> |
Push a tag to the registry |
docker image push --all-tags <name> |
Push all tags to the registry |
Docker Cache Management
| Command | Description |
|---|---|
docker image prune -a --filter "until=24h" |
Delete all unused images older than 24h |
docker system prune |
Delete all unused Docker objects |
Extended Run Commands
| Command | Description |
|---|---|
docker run <image> <args> |
Start an image with arguments. Overwrites CMD |
docker run --entrypoint="<command>" <image> |
Start an image with a different entrypoint |
Keywords in Dockerfile
| Command | Description |
|---|---|
FROM <baseimage> |
Set baseimage |
FROM <baseimage> as <name> |
Set baseimage and give the stage a name |
RUN <command> |
Execute a command in the container |
ENTRYPOINT ["<arg1>", "<arg2>"] |
Set the entry point. Is executed each time a container is started |
CMD ["<arg1>", "<arg2>"] |
Set default arguments for the entrypoint |
WORKDIR <path> |
Set the workdir in the container for all subsequent commands |
USER <user/user-id> |
Set the user in the container for all subsequent commands |
EXPOSE <port> |
Document required ports |
COPY <source> <target> |
Copy |
COPY --from=<stage> <source> <target> |
Copy |
ADD <source> <target> |
Copy |
ARG <name>[=<default>] |
Define build argument with optional default value |
ENV <name>=<default> |
Define environment variable in container |