Some examples
# PATH Options ==> IMAGE repository , tag
docker build . -t hello-world:1.0.1 # hello-world , 1.0.1
docker build git://github.com/naver/kapture # <none> , <none>
docker build git://github.com/naver/kapture#1.0.9 -t naver/kapture:1.0.9 # naver/kapture , 1.0.9-
imageis a saved and archived machine state (like an .img of an SD card). -
IMAGE IDuniquely identified an image. It is 64 digit hex code truncated to 12 digits (e.g. 91c95931e552). -
repositoryis a collection of images. 'ubuntu' is a repository. -
repository:tag(I 'll call itimage alias) is human-friendly alias to anIMAGE ID. Thetagpart usually refer to a version name, as such as 'hello-world:latest' -
registryis a server that stores and lets you distribute images. -
containeris a running instance based (and possibly modified) on an image. -
CONTAINER IDuniquely identified a container. -
NAMEis an alias toCONTAINER ID.
You can customize the default formatting of docker ps command by setting the .docker/config.json
mkdir ~/.docker && nano ~/.docker/config.jsonFor example:
{
"psFormat": "table {{.Names}}\\t{{.Status}}\\t{{.RunningFor}}\\t{{.Image}}"
}| Placeholder | Description |
|---|---|
.ID |
Container ID |
.Image |
Image ID |
.Command |
Quoted command |
.CreatedAt |
Time when the container was created. |
.RunningFor |
Elapsed time since the container was started. |
.Ports |
Exposed ports. |
.State |
Container status (for example; “created”, “running”, “exited”). |
.Status |
Container status with details about duration and health-status. |
.Size |
Container disk size. |
.Names |
Container names. |
.Labels |
All labels assigned to the container. |
.Label |
Value of a specific label for this container. For example '{{.Label "com.docker.swarm.cpu"}}' |
.Mounts |
Names of the volumes mounted in this container. |
.Networks |
Names of the networks attached to this container. |
-
CMDis an instruction that is best to use if you need a default command which users can easily override. -
ENTRYPOINTis preferred when you want to define a container with a specific executable.
Prefer exec form (["echo", "Hello World"]) to prevent potential performance issues.
More : docker-cmd-vs-entrypoint
-
port: map the port from inside to outside the container. -
expose: don’t publish to the host machine - they’ll only be accessible to linked services. Only the internal port can be specified.
For Debian-based images, removing root from container can be done like this:
RUN groupadd -g 10001 dotnet \
&& useradd -u 10000 -g dotnet dotnet \
&& chown -R dotnet:dotnet /app
USER dotnet:dotnet|
Note
|
UIDs below 10000 are a security risk on several systems. |
see more on dockerfile-best-practices