Table of contents
- Task:
- Create a new user account that you want to use to run Docker containers.
- Add the new user to the "docker" group to give them permission to run Docker commands:
- Reboot the instance for the changes to take effect:
- Pull the desired image from Docker Hub:
- Run the container as the non-root user you created earlier:
- Use the docker inspect command to inspect the container's running processes and exposed ports.
- Use the docker logs command to view the container's log output.
- Use the docker stop and docker start commands to stop and start the container.
Task:
Create a new user account that you want to use to run Docker containers.
adduser abhijeet
Add the new user to the "docker" group to give them permission to run Docker commands:
sudo usermod -aG docker abhijeet
Reboot the instance for the changes to take effect:
sudo reboot
Pull the desired image from Docker Hub:
docker pull <image-name>
Run the container as the non-root user you created earlier:
docker run --user myuser <image-name>
Use the docker inspect
command to inspect the container's running processes and exposed ports.
docker inspect CONTAINER_ID
Use the docker logs
command to view the container's log output.
docker logs CONTAINER_ID
Use the docker stop
and docker start
commands to stop and start the container.
docker start/stop <container_id>