Docker Cheat Sheet

From Gejoreuy
Jump to navigation Jump to search

Run Container

 $ docker run -it centos

Run Container in Background

 $ docker run -itd --name my_centos centos

Run Container in Background and Set Its Timezone

 $ docker run -itd -e TZ=Asia/Jakarta --name my_centos centos

Enter Container Through Bash

 $ docker exec -it [container_name] bash

Commit New Docker Image

 $ docker commit -m "your message" -a "author" [container-id] [new-image-name]

Login to Docker Image Registry

 $ docker login [registry-address]

Example Login to Docker Hub Registry

 $ docker login

Push Image to Repository

 $ docker tag [source-image-name:tag] [registry-address]/[repository-name]/[remote-image-name:tag]
 $ docker push [registry-address]/[repository-name]/[remote-image-name:tag]

Example Push Image to Repository (Docker Hub)

 $ docker tag my_centos
 $ docker push

Change Docker Image Tag

 $ docker tag [old_image_name:tag] [new_image_name:tag]
 $ docker rmi [old_image_name]

Copy File from Host to Container

 $ docker cp foo.txt mycontainer:/foo.txt

Copy File from Container to Host

 $ docker cp mycontainer:/foo.txt foo.txt