How To Run nopCommerce On Linux Using Docker

nopCommerce 4.20 is running successfully with .NET Core and many of us want to run it on a Linux machine. In this article, we’ll see how to run a nopCommerce app on a Linux machine using Docker.

How To Run nopCommerce On Linux Using Docker
 
nopCommerce is an open-source eCommerce platform built with Microsoft technologies. nopCommerce 4.20 is running fully with .NET Core and many of us want to run it on a Linux machine. There are different ways to do that — the easiest way is using Docker. In this article, we’ll see how to run a nopCommerce app on a Linux machine using Docker.
 
Before proceeding further, let’s understand about Docker and its components that we will use in this article. 
 

Docker

 
Docker is a lightweight, open, and secure platform. It is a way to simplify the process of building, shipping, and running applications in a different environment. Docker bundles up all the dependencies of an application and runs it in a container. In a simple word, on the off chance that you need to use MSSQL, you do not need to download, install, and manage a bunch of packages, simply run the container with Docker and use it — as simple as that.
 

Image

 
An image is used to build a container, it has necessary files to run something on an operating system, like Windows or Ubuntu, and then it has your application framework along with database files that support that. So, if you’re using ASP.NET, NodeJS, or Python, Images have that typical code.
 

Container

 
Images are just the definitions which cannot be run directly. To run the images, we need containers. Containers are the instances that help to run images with a different configuration like port, IP Address, etc.
 

Docker Compose

 
Docker Compose is used to run multiple containers under a single instance. It creates a network with different containers, through the network containers can communicate with each other. So, if the application has a dependency on other containers, Docker Compose is the right fit.
 
As we tend to run a nopCommerce app with an MS SQL server, we'll use Docker Compose.
 

Assumptions

 
All commands in this post assume that -
  • You are running a Linux machine.
  • Docker is installed on your system.

 
Step 1 - Use Docker command without Sudo

 
Execution of Docker command requires root privileges and to add privilege, we have to add "sudo" prefix to execute the command. To make it easy, let's add your username to the Docker group so we don’t need to pass “sudo” every time we use a Docker command. 
  1. $sudo usermod -aG docker ${USER}  
To apply the changes, log out of the system and login again.
 

Step 2 - Check Docker version

 
As Docker is already installed on the system, check the version using the following command.
 
docker –v 
  1. adminvm@adminvm-VirtualBox:~$ docker -v  
  2. Docker version 18.09.7, build 2d0083d  
If it displays the version with no error message, we’re ready to go the next step.
 

Step 3 - Install Docker Compose

 
As we have to communicate nopCommerce with SQL Server containers, we need to install Docker Compose to the machine. Do keep in mind that Docker Compose needs to be installed separately; it doesn't install with default Docker installation.
 
Install Docker Compose with the following commands.
  1. sudo curl -L 
  2. "https://github.com/docker/compose/releases/download/1.22.0/docker-compose-$(uname -s)-$(uname -m)"  -o /usr/local/bin/docker-compose    
  3.   
  4. sudo mv /usr/local/bin/docker-compose /usr/bin/docker-compose    
  5.   
  6. sudo chmod +x /usr/bin/docker-compose     
Afterward, check the Docker Compose version with the following, and you should see the version there.
 
docker-compose -v
  1. adminvm@adminvm-VirtualBox:~$ docker-compose -v  
  2. docker-compose version 1.22.0, build f46880fe  
 

Step 4 - Understand “docker-compose.yml” file

 
Download nopCommerce 4.20 source code on your machine and open the docker-compose.yml file located at the root.
 
How To Run nopCommerce On Linux Using Docker
 
Let’s understand the parameters of this file.
 
Parameter
Description
version
It indicates the compose file version; version 3 is the most recent and recommended.
services
It contains a configuration that applies to each container.
It has all the information about the containers and images and environment variables. 
volumes Volumes are used to persist data generated by and used by Docker containers. 
 
This Compose file defines two services — “nopcommerce_web” and “nopcommerce_database”.
 
Parameter Description
nopcommerce_web
Application Service name
build:  .
The service uses an image that’s built from the Dockerfile in the current directory, and then binds the container and the host machine to the exposed port.
container_name Name of the web project container.
ports Bind container with port 80—container internal port and application port.
depends_on As web project has a dependency on database services, it has been defined under this section
nopcommerce_database Database service name.
image: "microsoft/mssql-server-linux" MSSQL image name, if it is not present in a local machine, it will be download while running the container.
environment The environment section defined the environment variables required to run the container. 
SA_PASSWORD DB password for the default user SA.
ACCEPT_EULA Confirm your acceptance of the End-User Licensing Agreement.
MSSQL_PID Set the SQL Server edition or product key. We are going to run it with SQL express.
 
 

Step 5 - Run Docker Compose 

 
Open the terminal where "docker-compose.yml" is located and hit the below command.
 
docker-compose up
  
How To Run nopCommerce On Linux Using Docker
 
This will download the required images, build the project, and start the containers; it will take some time — sit back and relax!
 
How To Run nopCommerce On Linux Using Docker 
 
Once the process is done, you should see the screen with logs, as below.
 
How To Run nopCommerce On Linux Using Docker
 

Step 6 - Check Running Containers

 
Open the second terminal and execute the command [docker ps]. It will list down all the running containers. You should see that both the containers - nopCommerce and SQL Server are running now. 
 
How To Run nopCommerce On Linux Using Docker 
 

Step 7 - Run nopCommerce store on a browser

 
Open a browser tab and hit the URL http://localhost:80. It will open the nopCommerce installation page.
 
How To Run nopCommerce On Linux Using Docker 
 

Step 8 - Pass the DB connection

 
Pass the database container name and password that has been defined in the yml file.
 
How To Run nopCommerce On Linux Using Docker 
 

Step 9 - Check the container status

 
Once the installation is done, you should see the connection reset page because our application container has stopped running.
 
How To Run nopCommerce On Linux Using Docker 
 
Execute the [docker ps] command again to see the running containers. You should see only one container of MSSQL is running.
 
How To Run nopCommerce On Linux Using Docker
 
To get a list of all the containers, execute the command [docker ps -a] 
 
How To Run nopCommerce On Linux Using Docker
 

Step 10 - Up the web container again

 
To run the web container again, run the command [docker container start <container-id>]. You can simply give the first three characters of the container Id.
 
How To Run nopCommerce On Linux Using Docker
 
Follow with the command to list the running containers. You should see both the containers are running now.
 
How To Run nopCommerce On Linux Using Docker
 

Step 11 - Go to the browser window and check the nopCommerce store

 
Go to the localhost and hit Refresh. You'll land up to the nopCommerce Homepage.
 
NopCommerce Home Page
 
Congratulations! 🎉 You’re running your nopCommerce first store on a Linux machine!!
 

Summary

 
In this article, we have learned how to run a nopCommerce store on a Linux machine and basic Docker commands.