-
Notifications
You must be signed in to change notification settings - Fork 9
/
my_lab
48 lines (47 loc) · 2.91 KB
/
my_lab
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
1. Make a docker file
FROM alpine
LABEL owner="RG"
LABEL description="Mydockerimage"
COPY abc.txt /opt/abc.txt
2. Now Create an image with, docker build .
3. Now When You run docker images, you see 2 created: coz one is base image
4. Now let's tag the image that got created with docker build -t myalpine:v1 .
5. When you do docker images, myalpine is repo name and v1 is tag name
6. let's add CMD ["ls"] in the docker file and run docker build -t myalpine:v2 .
7. let's do docker run myalpine:v2, this will show directories inside an image
8. Let's make a new dockerfile with dockerfile1 name by cp Dockerfile Dockerfile1 command
8.5 Make changes in CMD command let's do CMD ["ls", "/opt"]
9. Now docker build -t myalpine:v3 . will not work unless you pass parameter. follow below command
10. docker build -t myalpine:v3 -f Dockerfile1 .
11. docker images, see you will have now v3 tag image and can run sth like docker run myalpine:v3
12. Let's see the running processes with docker ps command
13. You can see that nothing is being running, coz we don't have any running processes.
14. If you want to run the process in deamon mode then you need to change the parameters
15. docker run -d -it myalpine:v3 sh , and run command ps -a , you see status up
16. docker ps will only show the running process
17. if you want only your 2 container_id's , you can run docker ps -q or docker ps | awk '{print $1}' | tail -2
18. to stop all 2, you can do --- docker stop $(docker ps -q)
19. docker system prune --to clean up your dead processes. do docker images (your images are there) but containers are cleaned up
20. let's run docker run -d -it --name "Testing" myalpine:v3 sh
21. docker ps
22. docker exec -it (container_id) sh (now you are inside that image
#### Mount the volume inside your container
1. docker run -d -it --name "VTesting" -v /home/ubuntu/docker/html:/opt/html myalpine:v3 sh
2 -v parameter will help to mount volume, and your location where it's actually available : where you want to mount it in container
3. let's see if it available or not
4. docker ps
5. docker exec -it (container_id) sh and go inside /opt -- you will see html folder and your file.
6. you can now make some modification to that file ,exit, docker ps, docker kill container_id, you can still see your changes in your actual file
7. vim Dockerfile-httpd
FROM httpd:2.4
LABEL owner:"rbngtm1"
COPY ./html/ /usr/local/apache2/htdocs/
8. docker build -t myhttpd:v1 -f Dockerfile-httpd .
9. docker run -d -it --name mywebsite -p 8080:80 myhttpd:v1
10. docker ps (it's up and running) (try your iP:8080)
#### Push docker images
1. docker login (will take you to docker hub) (but you will be storing in registary in private env like docker login registry.mycompany.)
2. but for testing purpose, let's just do docker login, keep your username and passwd
3. docker images
4. docker tag myhttpd:v1 reponamedockerhub/myhttpd:v1
5. docker push myhttpd:v1 reponamedockerhub/myhttpd:v1