Scavenger233 / Docker

Docker bullet points.
0 stars 0 forks source link

Notes for Docker #4

Open Scavenger233 opened 1 month ago

Scavenger233 commented 1 month ago

Commands

docker ps

docker ps -a

docker start --> start containers

docker stop

docker run  --> run images

docker run -p6001:6379 -d redis:4.0

docker run -p6000:6379 redis:4.0

docker run -p6001:6379 -d redis:4.0

docker images

docker pull redis/postgres

docker logs eee4669d9881

docker run -d -p6001:6379 --name redis40 redis:4.0

docker exec -it b14c46ca97a9 /bin/bash  //work with ID
root@b14c46ca97a9:/data# env
root@b14c46ca97a9:/# exit

docker exec -it redis40 /bin/bash  //work with name too

docker logs eee4669d9881 | tail

docker-compose -f filename.ymal up
docker-compose -f filename.ymal down
docker-compose -f filename.ymal up -d

docker build -t my-app:1.0 .
docker build -t appname:version fileLocation

docker images

docker run appName:version

docker ps -a | grep container-name

(base) pocky2333@s-Macbook techworld-js-docker-demo-app-master % docker exec -it 31682640f902 /bin/bash
OCI runtime exec failed: exec failed: unable to start container process: exec: "/bin/bash": stat /bin/bash: no such file or directory: unknown

What's next:
    Try Docker Debug for seamless, persistent debugging tools in any container or image → docker debug 31682640f902
    Learn more at https://docs.docker.com/go/debug-cli/
(base) pocky2333@s-Macbook techworld-js-docker-demo-app-master % docker exec -it 31682640f902 /bin/sh  
/home/app #

//sometimes containers don't have bash, we can use shell instead by /bin/sh
Scavenger233 commented 1 month ago

New tag and new build ans new push

(base) pocky2333@s-Macbook techworld-js-docker-demo-app-master % docker images
REPOSITORY      TAG       IMAGE ID       CREATED        SIZE
my-app          1.0       7d1c5b12522d   25 hours ago   208MB
mongo           latest    e87b7385b5f7   5 days ago     1.12GB
redis           latest    541209804a00   11 days ago    196MB
redis           6.2       e61cb5a1671c   11 days ago    180MB
postgres        latest    4ec37d2a07a0   2 weeks ago    635MB
mongo-express   latest    1b23d7976f02   7 months ago   285MB
redis           4.0       2e03fdd159f4   4 years ago    126MB
(base) pocky2333@s-Macbook techworld-js-docker-demo-app-master % docker tag my-app:latest 913524943826.dkr.ecr.us-east-1.amazonaws.com/my-app:1.0   
Error response from daemon: No such image: my-app:latest
(base) pocky2333@s-Macbook techworld-js-docker-demo-app-master % docker tag my-app:1.0 913524943826.dkr.ecr.us-east-1.amazonaws.com/my-app:1.0
(base) pocky2333@s-Macbook techworld-js-docker-demo-app-master % docker images 
REPOSITORY                                            TAG       IMAGE ID       CREATED        SIZE
913524943826.dkr.ecr.us-east-1.amazonaws.com/my-app   1.0       7d1c5b12522d   25 hours ago   208MB
my-app                                                1.0       7d1c5b12522d   25 hours ago   208MB
mongo                                                 latest    e87b7385b5f7   5 days ago     1.12GB
redis                                                 latest    541209804a00   11 days ago    196MB
redis                                                 6.2       e61cb5a1671c   11 days ago    180MB
postgres                                              latest    4ec37d2a07a0   2 weeks ago    635MB
mongo-express                                         latest    1b23d7976f02   7 months ago   285MB
redis                                                 4.0       2e03fdd159f4   4 years ago    126MB
(base) pocky2333@s-Macbook techworld-js-docker-demo-app-master % docker push 913524943826.dkr.ecr.us-east-1.amazonaws.com/my-app:1.0
The push refers to repository [913524943826.dkr.ecr.us-east-1.amazonaws.com/my-app]
29e5d40040c1: Pushed 
7565e6a3d9f2: Pushed 
f3f39adf0e01: Pushed 
4f4fb700ef54: Pushed 
454dedeaa4fb: Pushed 
8e517bab838c: Pushed 
7966f33ae15c: Pushed 
13577ee3c8c3: Pushed 
af415933fb78: Pushed 
1.0: digest: sha256:7d1c5b12522d7734175f63cad898729944011b537d5bafb3f533667be7f38614 size: 856
(base) pocky2333@s-Macbook techworld-js-docker-demo-app-master % docker build -t my-app:1.1
ERROR: "docker buildx build" requires exactly 1 argument.
See 'docker buildx build --help'.

Usage:  docker buildx build [OPTIONS] PATH | URL | -

Start a build
(base) pocky2333@s-Macbook techworld-js-docker-demo-app-master % docker build -t my-app:1.1 .
[+] Building 1.3s (11/11) FINISHED                                                                                                           docker:desktop-linux
 => [internal] load build definition from Dockerfile                                                                                                         0.0s
 => => transferring dockerfile: 451B                                                                                                                         0.0s
 => [internal] load metadata for docker.io/library/node:13-alpine                                                                                            1.1s
 => [auth] library/node:pull token for registry-1.docker.io                                                                                                  0.0s
 => [internal] load .dockerignore                                                                                                                            0.0s
 => => transferring context: 2B                                                                                                                              0.0s
 => [1/5] FROM docker.io/library/node:13-alpine@sha256:527c70f74817f6f6b5853588c28de33459178ab72421f1fb7b63a281ab670258                                      0.0s
 => => resolve docker.io/library/node:13-alpine@sha256:527c70f74817f6f6b5853588c28de33459178ab72421f1fb7b63a281ab670258                                      0.0s
 => [internal] load build context                                                                                                                            0.0s
 => => transferring context: 39.78kB                                                                                                                         0.0s
 => CACHED [2/5] RUN mkdir -p /home/app                                                                                                                      0.0s
 => CACHED [3/5] COPY ./app /home/app                                                                                                                        0.0s
 => CACHED [4/5] WORKDIR /home/app                                                                                                                           0.0s
 => CACHED [5/5] RUN npm install                                                                                                                             0.0s
 => exporting to image                                                                                                                                       0.0s
 => => exporting layers                                                                                                                                      0.0s
 => => exporting manifest sha256:50f0676e7d8113aec722b4ffab9e35c11eac17b6ddd6dc3dcb2dd4872dddd772                                                            0.0s
 => => exporting config sha256:334c9a8b67f83c5737b3c7eff7d137e8467f4140de74d1c3737bb36d9e6106b1                                                              0.0s
 => => exporting attestation manifest sha256:2bc370aaa24bbf55ea19cc3f936a2cdf6294d1ce2700c5028ecbb44115194b6f                                                0.0s
 => => exporting manifest list sha256:ee3883e9d28ab8622177aec25af70dab9ab0aaaeea8ac6b300b959f944536e07                                                       0.0s
 => => naming to docker.io/library/my-app:1.1                                                                                                                0.0s
 => => unpacking to docker.io/library/my-app:1.1                                                                                                             0.0s

What's next:
    View a summary of image vulnerabilities and recommendations → docker scout quickview 
(base) pocky2333@s-Macbook techworld-js-docker-demo-app-master % docker images
REPOSITORY                                            TAG       IMAGE ID       CREATED        SIZE
913524943826.dkr.ecr.us-east-1.amazonaws.com/my-app   1.0       7d1c5b12522d   25 hours ago   208MB
my-app                                                1.0       7d1c5b12522d   25 hours ago   208MB
my-app                                                1.1       ee3883e9d28a   25 hours ago   208MB
mongo                                                 latest    e87b7385b5f7   5 days ago     1.12GB
redis                                                 latest    541209804a00   11 days ago    196MB
redis                                                 6.2       e61cb5a1671c   11 days ago    180MB
postgres                                              latest    4ec37d2a07a0   2 weeks ago    635MB
mongo-express                                         latest    1b23d7976f02   7 months ago   285MB
redis                                                 4.0       2e03fdd159f4   4 years ago    126MB
(base) pocky2333@s-Macbook techworld-js-docker-demo-app-master % docker tag my-app:1.1 913524943826.dkr.ecr.us-east-1.amazonaws.com/my-app:1.1
(base) pocky2333@s-Macbook techworld-js-docker-demo-app-master % docker images
REPOSITORY                                            TAG       IMAGE ID       CREATED        SIZE
my-app                                                1.0       7d1c5b12522d   25 hours ago   208MB
913524943826.dkr.ecr.us-east-1.amazonaws.com/my-app   1.0       7d1c5b12522d   25 hours ago   208MB
913524943826.dkr.ecr.us-east-1.amazonaws.com/my-app   1.1       ee3883e9d28a   25 hours ago   208MB
my-app                                                1.1       ee3883e9d28a   25 hours ago   208MB
mongo                                                 latest    e87b7385b5f7   5 days ago     1.12GB
redis                                                 latest    541209804a00   11 days ago    196MB
redis                                                 6.2       e61cb5a1671c   11 days ago    180MB
postgres                                              latest    4ec37d2a07a0   2 weeks ago    635MB
mongo-express                                         latest    1b23d7976f02   7 months ago   285MB
redis                                                 4.0       2e03fdd159f4   4 years ago    126MB
(base) pocky2333@s-Macbook techworld-js-docker-demo-app-master % docker push 913524943826.dkr.ecr.us-east-1.amazonaws.com/my-app:1.1
The push refers to repository [913524943826.dkr.ecr.us-east-1.amazonaws.com/my-app]
4f4fb700ef54: Layer already exists 
f3f39adf0e01: Layer already exists 
3a02c90a67e9: Pushed 
8e517bab838c: Layer already exists 
7565e6a3d9f2: Layer already exists 
13577ee3c8c3: Layer already exists 
af415933fb78: Layer already exists 
29e5d40040c1: Layer already exists 
7966f33ae15c: Layer already exists 
1.1: digest: sha256:ee3883e9d28ab8622177aec25af70dab9ab0aaaeea8ac6b300b959f944536e07 size: 856
(base) pocky2333@s-Macbook techworld-js-docker-demo-app-master % 
Scavenger233 commented 1 month ago

https://us-east-1.console.aws.amazon.com/ecr/repositories/private/913524943826/my-app?region=us-east-1 Where you can check new tag history