Bootstrap FreeKB - Docker - Run a command in a container using the docker run command
Docker - Run a command in a container using the docker run command

Updated:   |  Docker articles

This assumes you have installed Docker on Linux and Docker is running.

A Docker image contains the code used to create a Docker container, such as creating a Nginx web server, or a mySQL server, or a home grown app, and the list goes on. In this way, an image is like a template used to create a container. An image is kind of like a virtual machine, but much more light weight, using significantly less storage a memory (containers are usually megabytes in size).

 

At a high level, there are a few different ways to run a command in a Docker container.

In this example, I create a NodeJS container using the docker run command and append npm start at the end of the command to run the npm start command in the container.

~]$ sudo docker run --name my-nodejs-container --publish 0.0.0.0:8888:8888 --detach --volume my-nodejs-image:latest npm start

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 42e5b0 in the box below so that we can be sure you are a human.