Acesess The Container Shell

1. Changing file content : Now we are going to use the container shell to change the content of the user_env.txt file inside the docker container file system. Note that the user_env.txt file in you local machine will be different then the docker container user_env.txt file as each docker container has its own file system. To change the content of the file we first need to get into the container shell using the below command

docker exec -it container_id /bin/bash

The above commands will get you inside the docker container shell, container_id is the id if the container which we got using the docker ps command. Now you can execute commands using the shell. We are going to change the content of user_env.txt using the below command

sh -c ‘echo “GFG” > /user_env.txt’

The above command changed the content of the ser_env.txt file inside the docker container, now when you reload the below url it should display GFG.

Docker – Containers & Shells

Docker is a set of platforms as a service (PaaS) products that use Operating system-level virtualization to deliver software in packages called containers. Containers are isolated from one another and bundle their own software, libraries, and configuration files; they can communicate with each other through well-defined channels. All containers are run by a single operating system kernel and therefore use fewer resources than a virtual machine.

Similar Reads

What Is Docker?

Docker is a containerization platform that allows you to package code and dependencies into a Docker image that can be run on any machine. Docker allows your application to be separated from your infrastructure. The image that you created is portable, so you can run it on any machine that has Docker installed. To know how to install Docker refers to How to Install Docker....

What Are Containers?

Containers are lightweight piece of software that contains all the code, libraries, and dependencies that the application needs to run. Containers do not have their own operating system, they get resources from the host operating system. Because they do not have an operating system of their own they are lightweight. They are also easily portable as they contain all the libraries and the dependencies to run the application....

What Are Shells?

Shell is a program that is responsible for executing the command provided in the command prompt. It breaks down the command into smaller units called tokens and then executes them. It is an interface between the operating system and the user. The command prompt takes input from the user and gives it to the shell to execute it and the shell then returns the response to be displayed on the command prompt....

How To Run Containers In Docker?

To understand the role of shea l in a container, we are going to consider a simple example. We will create a file name user_env.txt which stores the value “Anshul” signifying the user. We will write a Python script with / endpoint which returns the value stored in the file user_env.txt. We will then create a dockerFile for creating image of the python script. Then we will start a container using that image....

Acesess The Container Shell

...

FAQs On Docker Images For Scaling Applications

1. Changing file content : Now we are going to use the container shell to change the content of the user_env.txt file inside the docker container file system. Note that the user_env.txt file in you local machine will be different then the docker container user_env.txt file as each docker container has its own file system. To change the content of the file we first need to get into the container shell using the below command...

Contact Us