VOOZH about

URL: https://thenewstack.io/containers/how-to-deploy-a-container-with-docker/

⇱ Container Basics: How to Deploy a Container with Docker - The New Stack


TNS
SUBSCRIBE
Join our community of software engineering leaders and aspirational developers. Always stay in-the-know by getting the most important news and exclusive content delivered fresh to your inbox to learn more about at-scale software development.
REQUIRED
It seems that you've previously unsubscribed from our newsletter in the past. Click the button below to open the re-subscribe form in a new tab. When you're done, simply close that tab and continue with this form to complete your subscription.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.
Welcome and thank you for joining The New Stack community!
Please answer a few simple questions to help us deliver the news and resources you are interested in.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Great to meet you!
Tell us a bit about your job so we can cover the topics you find most relevant.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Welcome!

We’re so glad you’re here. You can expect all the best TNS content to arrive Monday through Friday to keep you on top of the news and at the top of your game.

What’s next?

Check your inbox for a confirmation email where you can adjust your preferences and even join additional groups.

Follow TNS on your favorite social media networks.

Become a TNS follower on LinkedIn.

Check out the latest featured and trending stories while you wait for your first TNS newsletter.

PREV
1 of 2
NEXT
VOXPOP
As a JavaScript developer, what non-React tools do you use most often?
Angular
0%
Astro
0%
Svelte
0%
Vue.js
0%
Other
0%
I only use React
0%
I don't use JavaScript
0%
Thanks for your opinion! Subscribe below to get the final results, published exclusively in our TNS Update newsletter:
NEW! Try Stackie AI
From clobbered drafts to real-time sync
Apr 14th 2026 10:00am, by David Moore
TypeScript 6.0 RC arrives as a bridge to a faster future
Mar 14th 2026 9:00am, by Darryl K. Taft
Mastra empowers web devs to build AI agents in TypeScript
Jan 28th 2026 11:00am, by Loraine Lawson
2019-05-14 09:05:28
Container Basics: How to Deploy a Container with Docker
tutorial,
Containers

Container Basics: How to Deploy a Container with Docker

Instead of installing the operating system, followed by the server software, followed by the deployment of your perfectly-crafted app or site, you could simply develop everything in a self-contained bundle and roll it out with a single command. That’s one of the many benefits of using containers.
May 14th, 2019 9:05am by Jack Wallen
👁 Featued image for: Container Basics: How to Deploy a Container with Docker
Feature image by Daniela Dimitrova from Pixabay.

Imagine, in order to roll out a website, that you don’t have to install a full-blown server from bare metal up. Instead of installing the operating system, followed by the server software, followed by the deployment of your perfectly-crafted app or site, you could simply develop everything in a self-contained bundle and roll it out with a single command.

That’s one of the many benefits of using containers. They make the dev and deploy cycle incredible efficient. But how do you deploy those containers? I want to walk you through that process here. We’ll focus on deploying a basic NGINX web server, as a container, on Ubuntu Server 18.04. All of this will be done with the help of Docker.

What You’ll Need

In order to successfully deploy NGINX as a container, you’ll need to have the following:

That’s it. With those two pieces in hand, you’re ready to go.

A Gentle Reminder

Every container you deploy will be based on an image pulled from DockerHub. You can pull down a single image and use it as often as you like. There are also numerous images on DockerHub for a single application or platform. Take, for instance, NGINX. If you search for NGINX on DockerHub, you’ll come up with around 56,172 entries. That doesn’t mean each of those entries is a viable image for you to use.

Images are named like so:

name/descriptive-name

For example, with NGINX, you might find an image named:

bitwarden/nginx (a reverse proxy NGINX image)

Or you might find:

nginx/nginx-ingress (NGINX Ingress controller for Kubernetes)

So you see, there are images for just about every need.

At this time, there is only one image you want to focus on. That image is the official release from NGINX.

Pulling the Image

Before you can use an image, it has to be saved on your local drive. There are two ways to do this:

  • Directly, with the pull command.
  • Indirectly, during the container deployment process.

To pull an image from DockerHub, you would open a terminal window and issue the command:

docker pull nginx

If you wanted to pull the Ingress image, that command would be:

docker pull nginx/nginx-ingress

Once you’ve pulled down the image you want, you can make sure it’s there with the command:

docker images

The above command will list out all of the images you’ve pulled (Figure A).

👁 Image

Figure A: Both the NGINX and nginx/nginx-ingress images are available to be used.

Do use caution when pulling down random images. Why? Because you never know what went into creating them. A container could contain malicious code, which could wreak havoc on your network or data. Because of this, it’s always best to only work with the official images (such as the NGINX image).

Deploying the Container

It’s now time to deploy the container. Had you not already pulled down the image, the requested image would be pulled down during the deployment phase. Since we pulled down the official NGINX image, we’ll be using that.

To deploy a container, you use the docker command like so:

docker run --name NAME -p PORTS IMAGE

Where:

  • NAME equals a name you want to give the container (this could be anything, like nginx-webserver).
  • PORTS the ports you want to use (in the form NETWORK PORT:CONTAINER PORT).
  • IMAGE the image to be used for the container (such as nginx).

So, the very basic command to deploy our NGINX container would be:

docker run --name nginx-webserver -p 80:80 nginx

The container would be deployed and the NGINX web server would be available to your local network on port 80. What if, however, port 80 was already taken on the server being used to deploy the container? You could deploy it on network port 8080, like so:

docker run --name nginx-webserver -p 8080:80 nginx

At this point, you might see the next issue. After running one of the above commands, the bash prompt isn’t returned (Figure B).

👁 Image

Figure B: The container gives us feedback as the NGINX-powered site is visited, but it doesn’t give us our prompt back.

Detached Mode

How do you run a container, and get your bash prompt back? To do this, you must run the container in detached mode. Before you do that, you have to kill the current container with the keyboard combination [Ctrl]+. That combination will give you back the prompt and kill the container.

To make sure a container isn’t still running, issue the command:

docker ps -a

This will list out all containers and their status (Figure C).

👁 Image
If the container were still running, we’d have to kill it before we could deploy another container on the same port (otherwise the ports would conflict, preventing the container from deploying). To kill a running container, you first need the Container ID (a random string of characters). This string is presented when the docker ps -a command is issued. To kill a running container, issue the command:

docker stop CONTAINER_ID

Where CONTAINER_ID is the ID of the container in question.

You can then delete the container with the command:

docker rm CONTAINER_ID

Where CONTAINER_ID is the ID of the container in question.

Do note, you don’t have to type out the full Container ID, as the first four characters of the string will suffice.

Now, to deploy the container in detached mode, the command would be:

docker run --name nginx-webserver -p 80:80 -d nginx

This time you’ll not only get your prompt back, but Docker will display the Container ID for you (Figure D).

👁 Image

Figure D. Our NGINX container, running in detached mode.

Accessing the Running Container

What if you wanted to work on the running container? Say you want to make changes to NGINX or even start developing the website it will display? To do that, you have to access the container. For this, you need the Container ID. With the ID in hand, issue the command:

docker exec -it CONTAINER_IT bash

Where CONTAINER_ID is the ID of the container.

You should now be in the running container prompt (Figure E), where you can start working on the NGINX server.

👁 Image

Figure E: The NGINX container prompt, ready for work.

To exit the container, simply type the command exit.

Easier Than You Thought

Hopefully, by now, you’re seeing that container deployment isn’t nearly as challenging as you thought. With the help of Docker, you can be rolling out apps and services like a pro … in minutes.

TRENDING STORIES
Jack Wallen is what happens when a Gen Xer mind-melds with present-day snark. Jack is a seeker of truth and a writer of words with a quantum mechanical pencil and a disjointed beat of sound and soul. Although he resides...
Read more from Jack Wallen
SHARE THIS STORY
TRENDING STORIES
TNS owner Insight Partners is an investor in: Docker.
SHARE THIS STORY
TRENDING STORIES
TNS DAILY NEWSLETTER Receive a free roundup of the most recent TNS articles in your inbox each day.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.