Docker details

 

touch Dockerfile
# Use an official Ubuntu as a base image
FROM ubuntu:latest

# Set the working directory inside the container
WORKDIR /app

# Copy the current directory contents into the container at /app
COPY . /app

# Install any needed packages specified in requirements.txt
RUN apt-get update && apt-get install -y \
    python3 \
    && rm -rf /var/lib/apt/lists/*

# Make port 80 available to the world outside this container
EXPOSE 80

# Define environment variable
ENV NAME World

# Run app.py when the container launches
CMD ["python3", "app.py"]

docker build -t your-image-name .

to delete swp files :-
find . -maxdepth 1 -type f -name ".*.sw[klmnop]" -delete


docker ps  ; docker kill container_id
docker ps -a ; docker rm container_id
docker image ls ; docker rmi container_id 

How to build image:-
------------------------------------------------
[root@pm Public]# docker ps
CONTAINER ID   IMAGE       COMMAND        CREATED              STATUS              PORTS     NAMES
d77afae4b691   ubuntu_go   "sleep 5000"   About a minute ago   Up About a minute             modest_mendel
[root@pm Public]# docker exec -u 0 -it d77af /bin/bash
root@d77afae4b691:/# service ssh start
 * Starting OpenBSD Secure Shell server sshd                                                                                                                                     [ OK ]
root@d77afae4b691:/#
root@d77afae4b691:/#
root@d77afae4b691:/#
root@d77afae4b691:/# exit
exit
[root@pm Public]# clear
[root@pm Public]# docker ps
CONTAINER ID   IMAGE       COMMAND        CREATED         STATUS         PORTS     NAMES
d77afae4b691   ubuntu_go   "sleep 5000"   4 minutes ago   Up 4 minutes             modest_mendel
[root@pm Public]#
[root@pm Public]# docker kill d77af
d77af
[root@pm Public]# docker ps -a
CONTAINER ID   IMAGE         COMMAND                  CREATED         STATUS                       PORTS     NAMES
d77afae4b691   ubuntu_go     "sleep 5000"             4 minutes ago   Exited (137) 2 seconds ago             modest_mendel
14622d31b9d4   ubuntu        "sleep 5000"             25 hours ago    Exited (137) 25 hours ago              interesting_khayyam
f27e19102e2a   ubuntu        "sleep 5000"             30 hours ago    Exited (0) 29 hours ago                blissful_banach
282770453e88   ubuntu        "sleep 2000"             30 hours ago    Exited (137) 30 hours ago              zen_einstein
b28c2aa920b2   ubuntu        "sleep 2000"             30 hours ago    Exited (137) 30 hours ago              funny_chebyshev
9d631e44effb   ubuntu        "sleep 1000"             2 days ago      Exited (137) 2 days ago                unruffled_noether
b26a99bc61d7   ubuntu        "/bin/bash"              2 days ago      Exited (0) 2 days ago                  practical_babbage
bfd28df139c9   nginx         "/docker-entrypoint.…"   2 days ago      Exited (0) 2 days ago                  naughty_hermann
08e49eb750c1   nginx         "/docker-entrypoint.…"   2 days ago      Exited (0) 2 days ago                  wizardly_dijkstra
b4f8fa75d3d8   hello-world   "/hello"                 2 days ago      Exited (0) 2 days ago                  hungry_ride
[root@pm Public]#
[root@pm Public]# docker rm d77af
d77af
[root@pm Public]# docker image ls
REPOSITORY    TAG       IMAGE ID       CREATED         SIZE
ubuntu_go     latest    139f1fcf4e80   5 minutes ago   237MB
ubuntu        latest    ca2b0f26964c   9 days ago      77.9MB
nginx         latest    e4720093a3c1   3 weeks ago     187MB
hello-world   latest    d2c94e258dcb   10 months ago   13.3kB
[root@pm Public]#
[root@pm Public]# docker rmi 139f1f
Untagged: ubuntu_go:latest
Deleted: sha256:139f1fcf4e805252f997309f363cdf1f5723a0cddef48a152b6036cbd42f99e1
[root@pm Public]#
[root@pm Public]# docker image ls
REPOSITORY    TAG       IMAGE ID       CREATED         SIZE
ubuntu        latest    ca2b0f26964c   9 days ago      77.9MB
nginx         latest    e4720093a3c1   3 weeks ago     187MB
hello-world   latest    d2c94e258dcb   10 months ago   13.3kB
[root@pm Public]#
[root@pm Public]#
[root@pm Public]# ls
Dockerfile
[root@pm Public]# cat Dockerfile
# docker file

from ubuntu:latest
run apt-get update -y && \
apt-get install openssh-client -y && \
apt-get install openssh-server -y

run useradd -m oracle ; echo "oracle:k" | chpasswd

cmd ["/usr/sbin/sshd","-D"]

[root@pm Public]#
[root@pm Public]#
[root@pm Public]#
[root@pm Public]# # to build docker image from dockerfile
[root@pm Public]# docker build -t ubuntu_golive .
[+] Building 2.3s (7/7) FINISHED                                                                                                                                         docker:default
 => [internal] load build definition from Dockerfile                                                                                                                               0.3s
 => => transferring dockerfile: 318B                                                                                                                                               0.0s
 => [internal] load metadata for docker.io/library/ubuntu:latest                                                                                                                   0.0s
 => [internal] load .dockerignore                                                                                                                                                  0.3s
 => => transferring context: 2B                                                                                                                                                    0.0s
 => [1/3] FROM docker.io/library/ubuntu:latest                                                                                                                                     0.0s
 => CACHED [2/3] RUN apt-get update -y && apt-get install openssh-client -y && apt-get install openssh-server -y                                                                   0.0s
 => CACHED [3/3] RUN useradd -m oracle ; echo "oracle:k" | chpasswd                                                                                                                0.0s
 => exporting to image                                                                                                                                                             0.2s
 => => exporting layers                                                                                                                                                            0.0s
 => => writing image sha256:139f1fcf4e805252f997309f363cdf1f5723a0cddef48a152b6036cbd42f99e1                                                                                       0.0s
 => => naming to docker.io/library/ubuntu_golive                                                                                                                                   0.2s
[root@pm Public]#
[root@pm Public]#
[root@pm Public]# docker image ls
REPOSITORY      TAG       IMAGE ID       CREATED         SIZE
ubuntu_golive   latest    139f1fcf4e80   6 minutes ago   237MB
ubuntu          latest    ca2b0f26964c   9 days ago      77.9MB
nginx           latest    e4720093a3c1   3 weeks ago     187MB
hello-world     latest    d2c94e258dcb   10 months ago   13.3kB
[root@pm Public]#
[root@pm Public]#
[root@pm Public]#
[root@pm Public]# docker run -d 139f1fcf4e80 sleep 5000
b1c75746ebed0a7fa87c0734d271df890c0c5eb32b3d96939993118220d11e43
[root@pm Public]#
[root@pm Public]#
[root@pm Public]# # docker running in background
[root@pm Public]#
[root@pm Public]#
[root@pm Public]# #  login inside docker as root user
[root@pm Public]#
[root@pm Public]#
[root@pm Public]# docker exec -u 0 -it 139f1fcf4e80 /bin/bash
Error response from daemon: No such container: 139f1fcf4e80
[root@pm Public]#
[root@pm Public]#
[root@pm Public]#
[root@pm Public]# docker ps
CONTAINER ID   IMAGE          COMMAND        CREATED          STATUS          PORTS     NAMES
b1c75746ebed   139f1fcf4e80   "sleep 5000"   42 seconds ago   Up 40 seconds             mystifying_visvesvaraya
[root@pm Public]#
[root@pm Public]#
[root@pm Public]#
[root@pm Public]# docker exec -u 0 -it b1c75746ebed /bin/bash
root@b1c75746ebed:/#
root@b1c75746ebed:/#
root@b1c75746ebed:/#
root@b1c75746ebed:/# whoami
root
root@b1c75746ebed:/# uname -a
Linux b1c75746ebed 5.4.17-2136.328.3.el8uek.x86_64 #2 SMP Thu Jan 18 15:56:59 PST 2024 x86_64 x86_64 x86_64 GNU/Linux
root@b1c75746ebed:/#
root@b1c75746ebed:/#
root@b1c75746ebed:/# hostname
b1c75746ebed
root@b1c75746ebed:/# 
[root@pm Public]# docker exec -u oracle -it b1c75746ebed /bin/bash
oracle@b1c75746ebed:/$ whoami
oracle
oracle@b1c75746ebed:/$

----------------------------------------------------------------------------

Comments

Popular posts from this blog

typing using javascript html css