2025年6月22日 星期日

Handbook - docker

FAQ


Q: How to customize a container's hostname?

A:

    docker run -dit -p ${SSH_PORT}:22 \

               -v /build:/work \

               -v /home/:/home/ \

               -v /nas:/HOUSE \

               -v /etc/profile.d:/etc/profile.d \

               -v /etc/group:/etc/group:ro \

               -v /etc/passwd:/etc/passwd:ro \

               -v /etc/shadow:/etc/shadow:ro \

               -h ${CONTAINER_HOSTNAME} \

               --name ${CONTAINER_NAME} ${IMAGE_ID} /bin/bash


Q: How to address 
"docker load --input image.tar.gz in Ubuntu 20.04 fails with no space left on device"
A1: Build docker image on top of host OS, ie. Ubuntu 20.04 in this case.
or
The current best practice is:
docker system prune
Note the output from this command prior to accepting the consequences:
WARNING! This will remove:
  - all stopped containers
  - all networks not used by at least one container
  - all dangling images
  - all dangling build cache
Are you sure you want to continue? [y/N]
In other words, continuing with this command is permanent. Keep in mind that best practice is to treat stopped containers as ephemeral i.e. you should be designing your work with Docker to not keep these stopped containers around. You may want to consider using the --rm flag at runtime if you are not actively debugging your containers.
Make sure you read this answer, re: Volumes

You may also be interested in this answer, if docker system prune does not work for you.


--------------------------------------

# Check all the docker container/images

docker container ls

docker image ls

 

# Docker stop

docker stop <container id>

 

# Docker delete

docker rm <container id>

 

#Docker run

docker run <container id>

 

--------------------------------------

# Load docker image

docker load --input <xxx>.tar.gz

 

# change image name (optional)

docker image tag <docker image id> <image_name>:<version>

ex:

docker image tag b9ffda36b031 build_sa525m_env:latest

 

# run container

./execute.sh -p 1234 -n <container name> -I <container id>