TOOL » VIRTUAL_ENVIRONMENT » DOCKER

Build

Usage

shell
docker build OPTIONS CONTEXT
OptionDescription
-f --filePath to the Dockerfile.
-t --tagName and optionally tag in the name:tag format.
--no-cacheDo not use cache when building the image.
--pullAlways attempt to pull a newer version of the image.
--build-argSet build-time variables.

Dockerfile

dockerfile
FROM <image>

## Environment setup begin
ENV NAME World
RUN command
COPY . /code
WORKDIR /code
## Environment setup end

## Expose port to outside the container
EXPOSE 80

## Command to run when running the container
CMD ["binname", "arg"]

Apt-get

Sometimes it can fail to acquire packages. Add a retry option to solve this problem:

dockerfile
RUN apt-get update \
    && apt-get install -o 'Acquire::Retries=3' -y packages

Example

Build using the current directory as context and a custom Dockerfile.

shell
docker build --file dockerfile/prod --tag custom.registry:4567/imagename:latest .

Build while setting build-time variables.

shell
docker build --build-arg UID="$(id -u)" --build-arg GID="$(id -g)" .