docker run container code example

Example 1: docker access container

docker exec -it <mycontainer> bash
docker exec -it <mycontainer> sh ##for alpine

Example 2: how to start docker

systemctl start docker.service
#(OR)
systemctl start docker
# it will start docker

Example 3: docker compose run

# One single docker-compose.yml file
docker-compose up --build -d --remove-orphans

# Specify docker-compose.yml file to run
docker-compose -f docker-compose.yml up --build -d --remove-orphans

Example 4: docker run name

docker run --name <container name> -dp <local port>:<container port> <image>

Example 5: docker start container

$ docker start my_container

Example 6: docker run command on container

sudo docker exec -it <container name> <command>