How to deploy a Docker Container with VS Code
source link: https://www.techrepublic.com/article/deploy-docker-container-vs-code/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
How to deploy a Docker Container with VS Code
Jack Wallen shows you how to deploy a Docker container with the help of Microsoft VS Code.
Image: BalanceFormCreative/Adobe Stock
VS Code is one of the most popular open-source IDEs on the planet. It can work with a large number of languages, is quite user-friendly and available for Linux, macOS and Windows. Another very nice feature of the app is that it includes a vast array of extensions that add several extra abilities, such as working with containers.
With the help of a Docker extension, you can create containers, build images, deploy apps and more.
I’m going to show you how to make that happen, using VS Code on Pop!_OS Linux. You can do this on any platform that has Docker installed. I’ll walk you through the installation of both VS Code and Docker on my Ubuntu-based OS of choice. If you use a different platform, you’ll need to modify the installation process accordingly.
SEE: Hiring kit: Back-end Developer (TechRepublic Premium)
What you’ll need to deploy Docker
To get started with Docker on VS Code, you’ll need a running instance of an operating system that supports both and a user with admin privileges.
How to install Docker
The first thing we’ll do is install Docker.
Download and install the necessary GPG key:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
Now, add the official Docker repository:
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Install the necessary dependencies:
sudo apt-get install apt-transport-https ca-certificates curl gnupg lsb-release -y
Finally, we can install the latest version of the Docker engine:
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io -y
When the installation completes, add your user to the docker group with:
sudo usermod -aG docker $USER
Log out and log back in for the changes to take effect.
How to install VS Code
To install VS Code, head over to the official download page, open a terminal and run the following command:
sudo dpkg -i ~/Downloads/code*.deb
When the installation completes, open VS Code from your desktop menu.
How to install the Docker extension
Upon the first run of VS Code, it should detect that Docker is installed and ask if you want to install the Docker extension. If so, click install and you’re good to go. If not, click the gear icon near the bottom left of the VS Code window, and in the search field, type Docker. When the Docker extension appears, click the associated Install button (Figure A).
Figure A
Installing the Docker extension for VS Code.
After the extension installs, you should see any containers, images, and registries you’ve already created listed in the left pane.
How to deploy a container
In the VS Code window, click Terminal | New Terminal. With the terminal window open, let’s pull and run the getting-started Docker container with:
docker run -d -p 80:80 docker/getting-started
If port 80 is already taken, you can deploy it on external port 8080 with:
docker run -d -p 8080:80 docker/getting-started
Once the container has been deployed, you’ll see it listed under the CONTAINERS section. If you right-click that entry, you can take a number of actions such as View Logs, Attach Shell, Attach Visual Studio Code, Inspect, Open In Browser, Stop, Restart and Remove (Figure B).
Figure B
The right-click context menu for a running container in VS Code.
If you expand the entries for the Getting Started container under CONTAINERS, you can right-click any of those files and open them in VS Code for editing (Figure C).
Figure C
Editing a file within the running container.
Let’s say you’ve pulled down an image and want to run a container from that. Right-click the image from the IMAGES section and click Run.
This will deploy a container, based on the image, with the standard options. For example, if I click Run for the etherpad image, the command VS Code will execute is:
docker run --rm -d -p 9001:9001/tcp etherpad/etherpad:latest
You should fairly quickly see the etherpad container running under CONTAINERS, where you can right-click the entry and then click Open In Browser to experience the now running container.
And that’s pretty much the gist of deploying a container within VS Code. There’s so much you can do with these two tools together and this barely scratches the surface. But for those who like a traditional IDE for use within the realm of containers, this is a great combination.
Subscribe to TechRepublic’s How To Make Tech Work on YouTube for all the latest tech advice for business pros from Jack Wallen.
Developer Essentials Newsletter
From the hottest programming languages to the jobs with the highest salaries, get the developer news and tips you need to know.
Delivered ThursdaysRecommend
-
58
How to deploy a Windows container on Google Compute Engine ...
-
46
How to deploy a Windows container on Google Kubernetes Engine ...
-
7
3 days ago2021-05-17T00:00:00+02:00 by Wolfgang Ofner Updated 6 hours ago2021-05-19T22:25:07+02:00 11 min
-
5
How To Deploy OpenShift Container Platform 4.8 on KVM HypervisorSearch ComputingForGeeksIn this guide we wil...
-
4
How to Deploy Open-Source PACS on Nutanix Acropolis Container Services with Persistent Storage 08/17/2016 In this article I’ll demonstrate how to deploy an open-source PACS solution (DICOM server...
-
7
-
8
Deploy multi-container app to Azure App Service with docker-compose In this article, I will show how easy it is to deploy a multi-container application to Azure App Service using a docker-compose.yml file. This service is...
-
3
-
9
You have a self contained web app that runs in a docker container and want to deploy it on a cloud service. I will show you how easy it is to deploy your docker image to Azure App Services. I will, as an example use a simple Node.js Express w...
-
9
How to deploy Azure Functions as Custom Docker container using Azure DevOps 17 minute read | By Edison Garcia ...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK