- docker commit ContainerName ContainerName:Tag
How to create image from container.
It created 'commit_test:first' image.
$ docker run -i -t --name commit_test ubuntu:14.04 //Create ubuntu container
root@ac71ee960c10:/# echo test_first! >>first
$ docker commit commit_test commit_test:first //Create 'commit_test:first'image
sha256:e87f81e9b28ac369d9284d1b066219caed0ca22ce4539efb6825a9883257bdc4
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
commit_test first e87f81e9b28a 4 minutes ago 197MB
ubuntu 14.04 13b66b487594 5 months ago 197MB
or
$ docker run -i -t --name commit_container1 ubuntu:14.04
root@83c0e5f3db97:/# echo my first push >> test
$ docker commit commit_container1 myimage:0.0 //Create 'myimage:0.0'image
sha256:b19a821a88a18ab472d7e630380674bca4857b742cf89a27356996b49c3ffe75
How to create another image from 'commit_test:first' image.
1. Create the container from commit_test:first
$ docker run -i -t --name commit_test2 commit_test:first
2. Add 'second' file
root@c4bac8f4efd5:/# echo test_second! >> second
3. Create 'commit_test:second'image
$ docker commit -m 'my second commit' commit_test2 commit_test:second
sha256:dbf748f6d8c4a9b1e57fadcd88877f0483cbfe96bc29cba61d7b8d04f2407f39
- docker tag CurrentImageName NewImageName
Change or add the image name
1. Change the currnet image name(myimage:0.0) to new image name(nayapeach/myimage:0.0)
$ docker tag myimage:0.0 nayapeach/myimage:0.0
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
myimage 0.0 b19a821a88a1 4 minutes ago 197MB
nayapeach/myimage 0.0 b19a821a88a1 4 minutes ago 197MB
ubuntu 14.04 13b66b487594 5 months ago 197MB
- dockerfile
How to create dockerfile
1. I want to get ubuntu:14.04 in this image
FROM ubuntu:14.04
LABEL "purpose"="practice"
2. It will be installed below
RUN apt-get update
RUN apt-get install apache2 -y
3. Add test.html(in my local) to container directory(/var/www/html)
ADD test.html /var/www/html
4. Working directory
WORKDIR /var/www/html
5. Implement "echo hello >> test2.html" using "/bin/bash"
RUN ["/bin/bash", "-c", "echo hello >> test2.html"]
EXPOSE 80
CMD apachectl -DFOREGROUND
- docker build -t ImageName:tag DockerfileDirectory
How to build dockerfile
-t : tag, apply the tag to the image
$ docker build -t mybuild:0.0 ./
[+] Building 26.5s (11/11) FINISHED
...
- docker run -d -P
How to create the container with dockerfile
-P : All port, let all the image port connect to the host
$ docker run -d -P --name myserver mybuild:0.0
09f21c5c7428f05aa9f7985b4c56c76af981f003a66ff0a1abfee7e3787ae590
- docker images --filter
How to filter the image by labeling.
$ docker images --filter "label=purpose=practice"
REPOSITORY TAG IMAGE ID CREATED SIZE
mybuild 0.0 ea61530ee86f 22 minutes ago 221MB
- -dt
Docker Tool, is a command-line tool for Docker operations.
docker run -dt -v $HOME/yoon:/tmp --name joohyun_python python:3.8
Share $HOME/yoon:/tmp with python:3.8
⇡host ⇡container
named joohyun_python
'Docker' 카테고리의 다른 글
Run container with environment variable (0) | 2021.11.02 |
---|---|
How to run my python project on the docker (0) | 2021.10.22 |
Install the docker-compose (0) | 2021.04.12 |
MAC address, VLAN, LAN, -d, --driver, --subnet, --ip-range, -o, (0) | 2021.02.23 |
--net, HWaddr, --net-alias, grep, -c, round-robbin, dig (0) | 2021.02.22 |