Bobcares

How to connect to Docker container to manage the applications

by | Dec 23, 2016

Docker containers gained popularity as they enabled fast application deployment. This made them ideal solution for hosting applications and services. But to access these applications or services externally, we need to expose the docker ports.

While port forwarding is useful for end-users to access the container applications, developers and system administrators who manage the Docker infrastructure should have ways to connect to Docker containers from the backend.

Developers who code the applications in Docker containers would need to edit or modify these application files. Docker hosting providers who host services would have to adjust the container resources or perform administrative tasks in them.

All these activities require access to the containers. While SSH access is not possible to the Docker containers directly, the containers can be managed from the host machine with some simple steps.

[ You don’t have to lose your sleep to keep your customers happy. Our Hosting Support Specialists cover your servers and support your customers 24/7 at just $9.99/hour. ]

Today, we’ll discuss the 3 ways to connect to Docker containers from backend.

1. Connect to Docker container using ‘docker exec’

The main method to access Docker container from the host machine, is using the ‘docker exec’ command. For that, first login to the Docker host machine via SSH.

Then look up the Docker containers in the host machine and locate the one you want to access. You can do this with the ‘docker ps’ command:

 

connect to docker container - lookup the id

Lookup the Docker container

 

Once the docker container ID is identified, you can connect to it using ‘docker exec -it [container-id] /bin/bash’ command:

 

Connect to Docker container with docker exec

Connect to Docker container with docker exec

 

You will then be presented with a bash console inside the docker container, where you can perform the tasks specific to that container.

connect to docker container and execute commands

Execute commands in Docker container

 

[ Use your time to build your business. We’ll take care of your customers. Hire Our Hosting Support Specialists at $9.99/hr. ]

2. Connect to Docker container using ‘docker attach’

You can also use ‘docker attach [container-name]’ to connect to the container and execute commands in it:

 

Connect to Docker container using 'docker attach'

Connect to Docker container using ‘docker attach’

 

However, the use of ‘docker attach’ is deprecated now and ‘docker exec’ is the more preferred way to access the containers.

3. Execute commands in Docker containers without direct access

The commands ‘docker exec’ and ‘docker attach’ helps to connect to the Docker containers and generate a bash session in it. Via this session, it is easy to manage the files in that specific container.

But, to execute commands directly in the Docker containers, it is not always required to generate a bash session. You can also run commands directly using ‘docker exec’ command.

The ‘docker exec’ command can be executed by giving the command to be executed, as a parameter to it:

docker exec -it 'container-name' 'command-to-execute'

For instance, this snippet shows how we executed a command to create a file inside the container ‘berserk_darwin’ from the host machine.

connect to docker container and execute commands

Execute commands in container directly from host machine

 

In short..

Today, we saw the basic commands to be executed inorder to connect to and manage the docker containers. But in a typical Docker setup with a lot of containers, many commands have to be executed multiple times, which is a time consuming process.

To reduce the effort and time spent on managing Docker containers, we’ve automated most container management tasks with our custom scripts.

Our 24/7 Docker management team at Bobcares monitors and manages the Docker infrastructure for our customers, whose businesses range from webhosting services to software development.

If you’d like to know how to manage your Docker system and to get the best out of them for your business, we’d be happy to talk to you.

 

 

STOP SPENDING TIME ON SUPPORT!

Do you spend all day answering technical support queries?

Wish you had more time to focus on your business? Let us help you.

We free up your time by taking care of your customers and servers. Our engineers monitor your servers 24/7, and support your customers over help desk, live chat and phone.

HIRE SUPPORT SPECIALISTS AT $9.99/HR

Bobcares provides Outsourced Web Hosting Support and Outsourced Server Management for online businesses. Our services include 24/7 server support, help desk support, live chat support and phone support.

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.

Privacy Preference Center

Necessary

Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]
PHPSESSID
WHMCSpKDlPzh2chML

Statistics

Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid
smartlookCookie
_clck, _clsk, CLID, ANONCHK, MR, MUID, SM

Marketing

Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

_reb2bgeo - The visitor's geographical location

_reb2bloaded - Whether or not the script loaded for the visitor

_reb2bref - The referring URL for the visit

_reb2bsessionID - The visitor's RB2B session ID

_reb2buid - The visitor's RB2B user ID

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie
1P_JAR, NID, DV
NID
hblid
_reb2bgeo, _reb2bloaded, _reb2bref, _reb2bsessionID, _reb2buid

Security

These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.

SID, APISID, HSID, NID, PREF
SID, APISID, HSID, NID, PREF