Build Image

DevOps Docker Build Image

Common command

command description
docker build . Build the docker image from Dockerfile
docker build . --build-arg FOO=bar Build the docker image with specific argument
docker build -f {specific.Dockerfile} -t {image-tag} Build the docker image from specific.Dockerfile and naming this image as image-tag
docker build . --no-cache Build the docker image without cache
docker build . --no-cache -t {image-tag} Build the docker image without cache, and add the specific tag to this image
docker tag {image_name} {image-tag} Tag an existing image

Build image with specific Dockerfile

docker build -f=specific.Dockerfile -t=image tag .

docker build --no-cache -f="specific.Dockerfile" -t="kj/custom-image-name:0.1" .

Options

Options Description
--no-cache re-build the whole image without cache
-f assign the specific Dockerfile file name
-t the tag and version for this image

Dockerfile

Keyword

keyword description
FROM Load from the specific image as base
RUN Run the specific command
ARG Build argument
ENV Container environment variable. e.g. ENV {key} {value} or ENV {key1}={value1} {key2}={value2}
COPY Copy file from local to the container. e.g. COPY [--chown={user}:{group}] {source path}{distination path}
ADD Copy file from remote to the container and set the file permission to 600. e.g. ADD [--chown={user}:{group}] {source path}{distination path}
CMD Run the specific command
ENTRYPOINT Run the specific command and accept outside argument
WORKDIR Container default working directory