svg
Post Image
By Daniel Tanque26 de Outubro, 2023In DevOpsDockerLearning

Docker – Interoperability

Docker is a popular platform for developing, packaging, and deploying applications inside lightweight, self-contained containers. These containers are similar to virtual machines but more efficient and portable. Docker is used to package an application and its dependencies into a single unit called a container, ensuring that the application runs consistently across various environments, from a developer’s laptop to a production server.

In this article you will learn about how to setup ports so the container is accessible beyond the container itself, and as well how to save your data persistent by performing volume mapping.

Port Mapping

Every container has a IP address and a port. On launching the container is accessible on 0.0.0.0 or 172.17.0.2:5000 but that is only accessible through docker host, if you want to make it seen outside you need to map the ports from 172.17.0.2:5000 to 192.168.X.XXX for that you can do:

docker run -p 80:5000 <app image name>

Volume Mapping

The data is stored in the container if this container is gone the data is as well gone. Thus we need to map a folder inside the container with another app. For you can run the fallowing:

docker run -v /opt/dataDir:/var/lib/myqsl

Logs

To access the container logs you can run:

docker logs <name of a container>

Conclusion

Now you can operate your containers and make it accessible via network and via memory so you don’t lose your data.

svgDocker Basic Commands
svg
svgDocker - Dockerfile

Leave a reply