" .
# -d: as deamon
# --rm: exit and remove
docker run -d -p 80:80 -p 443:443 --name You can change the port mapping by directly editing the You can determine the [hash_of_the_container] via the docker build -t <image-name> --build-arg YOUR_ARG="<arg-value>" .
# -d: as deamon
# --rm: exit and remove
docker run -d -p 80:80 -p 443:443 --name <container-name> -v /opt/websites/app:/usr/share/nginx/html <image-name>
# enter the terminal
docker exec -it <container-name> /bin/bash
docker image remove <image-name>
docker container rm <container-name>
##
docker container rename <container-name> <new-container-name>
docker rm -f <container-name>
# build from github
docker build -t <image-name> <https://github.com/bndynet/docker.nginx.git[#<branch/tag>:<dir-for-context>]>
# Copy & Move
## Export and import containers
docker export container-name | gzip > container-name.gz
zcat container-name.gz | docker import - container-name
## Container image migration - Using this method, the data volumes will not be migrated, but it preserves the data of the application created inside the container.
docker commit container-id image-name
## Save and load images
docker save image-name > image-name.tar
cat image-name.tar | docker load
## copy files from container into host which does not need a running container
docker cp your-file-path-in-container your-host-location
# Publish
docker build -t bndynet/image-name:1.0 .
docker push bndynet/image-name:1.0
Networking
# bridge: The default network driver
# host: use the host’s networking directly
docker --network bridge|host|overlay|ipvlan
Change the port for the existing container
hostconfig.json
file at /var/lib/docker/containers/[hash_of_the_container]/hostconfig.json
or /var/snap/docker/common/var-lib-docker/containers/[hash_of_the_container]/hostconfig.json
, I believe, if You installed Docker as a snap.docker inspect <container_name>
command and the value of the "Id" field is the hash.
docker stop <container_name>
).docker start <container_name>
).Clear
docker system df # show disk space about docker
docker image prune -f # clear all images which is not used
Print Logs
# print the log for container
docker logs -f <container-name> 1>/dev/null
Example: