Working with Docker Containers

Working with Docker Containers

Docker is now available to install on all VPS and Dedicated Servers from InMotion Hosting, including Platform i, Unmanaged Cloud VPS, Control Web Panel, and cPanel-Managed VPS. Due to the complexity and potential system-level changes required, Docker installations are recommended for experienced users only.

Docker allows you to encapsulate your applications within containers, making them portable and easy to deploy across any system that supports Docker. You can create these containers using either Dockerfiles or pull pre-built images from the Docker Hub.

You can visit our What Is Docker article and the Docker Overview page for a comprehensive introduction to Docker.

Support Limitations

Please note that our Technical Support does not provide assistance with Docker-specific issues. For advanced support, you can reach out to our Managed Hosting Professional Services team.

Installing Docker

Installing Docker Community is relatively straightforward as they provide multiple different avenues to install it whether you prefer to use yum, their automated installers, or even a pre-built RPM/DEB package for the respective operating system. Included below is the respective installation documentation which covers every method of installing Docker CE (Community Edition).

Managing Containers

Checking Actively Running Containers

docker ps

Listing All Containers

docker ps -a

Deploying a Container from an Image

When you want to deploy an already existing Docker Hub image into a container; this is super easy to do as long as you know the correct tag associated with the container. In the example below, we will deploy the hello-world container from the Docker Hub.

docker run hello-world

This command downloads a test image and runs it in a container. When the container runs, it prints a confirmation message and exits to confirm your successful test of deploying a container from an image. Since this container exits after it runs, you would only find it in docker ps -a when searching for it in your container list.

Creating a Container from a Dockerfile

One of many ways to deploy a container is a Dockerfile similar to a “playbook” but more akin to “instructions” for an application/container to be built and run. A Dockerfile may or may not accompany source code and can be built and run with the below process. You can find more information on Docker’s Documentation portal.

cd /path/to/project
docker build -t your-application .

Once you have successfully built the image from their Dockerfile, you can simply run it using the APPLICATION_NAME that was used during the building process like below.

docker run your-application

Deploy a Container from a Docker Compose Playbook

For defining and managing multi-container setups, Docker Compose is utilized. While our support scope does not include troubleshooting Docker Compose scripts, we provide basic support for starting and stopping applications defined by a compose.yaml.

You can learn more about Docker Compose from their provided documentation.

Container Management Commands

Starting an Existing Container

If an existing container has stopped or exited, you can simply start it again:

docker start container_name_or_id

Stopping an Active Container

As long as a container is actively running and has not yet exited or stopped, you can stop a container:

docker stop container_name_or_id

Destroying an Existing Container

If a container is no longer needed, you can easily remove it with the rm docker command much like the Linux command:

docker rm container_name_or_id

How to Check Network Ports Used by a Container

Sometimes when deploying containers, they’ll automatically map their ports to an internal, local, or public IP address (typically 0.0.0.0) in order to facilitate networking on their ports. While these can be adjusted during container deployment (in many cases), we’re only going to focus on identifying the ports in use by a container here. You can learn more about Docker’s port mapping here on their documentation portal. You can also find information on this specific command here.

docker port APPLICATION_NAME

How to Check Docker Logs

Docker provides a really easy way to check on the logs of a container. You can simply run the below command to gain quick insight into a container’s state or get more specific with the log command to gain greater insight.

docker logs APPLICATION_NAME

Troubleshooting Common Docker Issues

Docker Won’t Start!

Restart the container or troubleshoot the Docker service using your system logs.

Excessive Disk Usage

Sometimes in development environments, Docker can become a space hog. You can easily clean up all unused assets including images, containers, and volumes:

docker system prune

Timezone Mismatch

Set the timezone when starting your container:

docker run -e TZ=$(cat /etc/timezone) your-image-name

My cPanel User Can’t Start Containers!

For a non-root user to manage Docker in any capacity, they’ll need to have the Docker group on the server. Simply add the user to the docker group to resolve the issue:

usermod -aG docker USER

General Docker FAQ

What is Docker?

Docker is a powerful platform designed to make it easier to create, deploy, and run applications by using containers. This means that the application will run on any other machine regardless of any customized settings that the machine might have that could differ from the machine used for writing and testing the code. Essentially, Docker streamlines the development lifecycle by providing a standard environment for development, testing, and production, ensuring consistency across multiple environments. Please see our What is Docker article for more detailed information.

Why use a Docker container instead of a Git Repo?

Docker provides a consistent environment for your application from development to production, isolating it from variations in the operating system and underlying infrastructure. In essence, while Git helps manage your code, Docker helps manage your entire application’s runtime environment.

Effectively this means that using a Git repo to manage an application will have it running on real-time updates whereas a Docker container receives updates from the Hub only when necessary.

Can we limit a container’s resources?

Yes! Docker provides mechanisms to limit resources for a container, such as CPU, memory, and I/O. This is crucial for ensuring that no single container can monopolize system resources, allowing for efficient resource utilization among all running containers. By using Docker’s resource management features, you can maintain system stability and optimize performance across all containers. You can learn more about managing a container’s resources from Docker’s Documentation Portal.

Can non-root users use Docker?

Yes! While Docker typically requires root privileges, it’s possible to configure Docker to be used by non-root users. This can be achieved by adding the user to the docker group, which grants them the ability to run Docker commands without root access. However, it’s important to be aware of the security implications, as users in the docker group can gain root access to the host system through the Docker daemon.

This option though can allow cPanel/CWP or even basic Shell users access to manage Docker and its containers!

Conclusion

Docker offers a robust solution for packaging and deploying applications consistently across various environments. By utilizing Docker on your InMotion Hosting VPS or Dedicated Server, you can streamline your development process, enhance portability, and ensure that your applications run seamlessly regardless of the underlying infrastructure. Whether managing individual containers or orchestrating multi-container deployments with Docker Compose, the tools, and commands provided above will help you effectively manage your Docker environment.

While Docker can significantly simplify application deployment, it requires a good understanding of container technologies and Linux system management. Should you encounter complexities beyond the basic setup and deployment, consider reaching out to our Managed Hosting Professional Services for expert assistance. Always ensure your Docker installations and configurations are maintained according to best practices to make the most out of this powerful technology.

Derrell Willis
Derrell Willis Manager, Developer Relations

More Articles by Derrell

Was this article helpful? Join the conversation!

Questions about our MailChannels Deployment? We have answers and are here to help!Learn More
+