FROM base:container
USER root # the user which the container runs
COPY ./host/file /container/file
ENV myenvironment=admin\
myenv2=password
RUN commands to be executed # eg. apt install software
USER myuser # switch back to user with less permission
ENTRYPOINT ["./entrypoint.sh"] # what the command container should run when starting the containerFROM the base container
ENV define environmental variables
- the env variable would be visible in the container by
envfunction
RUNexecute Linux commands in the container - split
RUNcommands to multiple lines - run
apt update && apt installin the sameRUNcommand - remove the apt cache afterward
&& rm -rf /var/lib/apt/lists/*
&& apt clean # officla ubuntu Docker image does this automaticallyCOPY copy file from host directory to container
CMD translate to entry point that runs after container starts, the CMD argument has to be in double quotes.
ENTRYPOINT is what the container will run as when exec
- by default, the entrypoint is
/bin/sh -cso withdocker exec container python app.pythe command run in the container will be/bin/sh -c python app.py - when entrypoint is set as
pythonthen executing the same command adobe will not work and for the same as above the exec command is nowdocker exec container app.py
Multi-arch Build
docker buildx build --platform linux/arm64 . -t caddytest- using
docker buildx, we can build an image that is compatible with many architectures