How can we help you?

Topics

How to build the NordVPN Docker image

Docker is a tool for easy deployment and management of applications in lightweight containers. Setting up NordVPN on a Docker container will secure your internet connection and protect your online privacy of other Docker containers as well.

 

Setting up the Docker environment

To build the NordVPN Docker image on Linux, you will first need to set up the Docker environment:

  1. Install the Docker engine on Linux.
  2. Once you have Docker installed, go to the terminal.
  3. Create a new directory for your image using this command:

    mkdir <directory name>


  4. Go to the created directory:

    cd <path/to/directory>


  5. Create a Dockerfile:

    touch Dockerfile


  6. Go to the file with your preferred text editor. In this example, we use nano.

    nano Dockerfile


  7. Copy and paste the following script into the file:

    FROM ubuntu:24.04

    RUN apt-get update && \ apt-get install -y --no-install-recommends wget apt-transport-https ca-certificates && \ apt-get install -y --no-install-recommends wget apt-transport-https ca-certificates && \
    wget -qO /etc/apt/trusted.gpg.d/nordvpn_public.asc https://repo.nordvpn.com/gpg/nordvpn_public.asc && \
    echo "deb https://repo.nordvpn.com/deb/nordvpn/debian stable main" > /etc/apt/sources.list.d/nordvpn.list && \
    apt-get update && \
    apt-get install -y --no-install-recommends nordvpn && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

    ENTRYPOINT /etc/init.d/nordvpn start && sleep 5 && /bin/bash -c "$@"
    CMD bash


  8. Click Ctrl + X, then Y, and finally, Enter to save and exit.

Now, you've successfully set up a Docker environment for further NordVPN Docker image building.

 

Building the NordVPN Docker image

After you have set up the environment in Docker, make sure you’re in the same directory you have just created, which stores the Dockerfile. Once you’re certain you’re in the correct directory, you can proceed with building the NordVPN Docker image by following these steps:

  1. Build the image with this command (add your desired image name):

    sudo docker build -t <image name> .


    Note: Do not forget the dot at the end of the command line.

  2. Run the image:

    sudo docker run -it --hostname mycontainer --cap-add=NET_ADMIN --sysctl net.ipv6.conf.all.disable_ipv6=0 <image name>


    Explanation:
    -it - instructs Docker to allocate a pseudo-TTY connected to the container’s stdin; creating an interactive bash shell in the container;
    --cap-add - needed to successfully run the NordVPN Daemon and connect to our servers;
    --sysctl net.ipv6.conf.all.disable_ipv6=0 - disables IPv6 traffic on Linux for the NordVPN container, making sure that there are no leaks after connecting to our servers.
    --hostname - the hostname for your container. The flag should be used to prevent Meshnet hostname from changing after restarting the Docker container.

  3. Login to NordVPN using a token method:

    nordvpn login --token <your token>

After the steps are done, you have successfully set up NordVPN Docker image.

For more detailed information on how to use Docker, check the Docker documentation.

Was this article helpful?
Thanks!