Hello lovely people! π During my day to day work with SONiC I have to launch new Docker containers and run commands within those containers. I usually have an ENTRYPOINT
or CMD
defined in my Dockerfile
which means that there is always a default process that starts when I run my Docker images. When I started working with Docker I would always use the attach
command to connect to a running container.
As an example, my Dockerfile
usually looks something like this:
FROM ubuntu:18.04
RUN apt-get update
RUN apt-get install -qy vim
COPY startup.py /startup.py
ENTRYPOINT ["python", "startup.py"]
I then build an image based on this Dockerfile
:
sudo docker build -t yasoob/imagename
Then I usually start up a container based on this latest image:
sudo docker run --name container_name -it -d yasoob/imagename:latest
At this point, I have two ways to connect to the Docker container. I can either use attach
or exec
. It is important to know the difference.
attach
allows you to connect and interact with a containerβs main process which has PID 1
exec
allows you to create a new process in the container#docker #attach #exec #images #entrypoint #dockerfile