Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

A lightweight Alpine based ocserv Docker image.

License

NotificationsYou must be signed in to change notification settings

Pezhvak/docker-ocserv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

About

A lightweight Alpine based ocserv Docker image.

You can either start by using thepre-built imageor bybuilding your own for more customization.

Table of Contents

Installation

Using Built Image

Apre-built image is available with the best configurations out of the box.Follow the instructions below to get up and running.

This setup includes:

  • 2 Device connections for each user (max-same-clients=2)
  • Up to 16 clients (max-clients=16)
  • 10.10.10.0/24 as the internal IP pool
  • Listens on port 1342 (can be changed by altering port mappings when you run the container)
  • Tunnels DNS to the server (tunnel-all-dns=true)

Note: All limits can be increased or set to be unlimited inocserv.confbybuilding your own image.

Versioning

By defaultdocker-compose.yml and the instructions written in this document use thelatesttag of the image which represents the latest commit in themaster branch. Besides that, tagged commits are alsoavailable if you want to make sure no breaking changes enter your setup. To do so, check outtags in our docker hub repo.

However, if you would like to get the cutting edge features you can always use thenext tag which represents thelatest commit in thedevelop branch.

STEP 1: Generating SSL Certificate

In any case, if you want to build the image yourself, run the pre-built one withdocker run or withdocker-compose,in all cases you will need an SSL certificate, It's up to you how you would like to generate it, perhaps you alreadyhave some kind of setup for that on your server, in case you don't, use thefollowingimage to generate one:

Note: You need to have a domain pointing to your server IP address and ports 80 and 443 available to be listenedto by the container for letsencrypt ACME challenge verification.

sudo docker run -it --rm --name certbot -p 80:80 -p 443:443 \    -v$(pwd)/certs:/etc/letsencrypt certbot/certbot \    certonly --standalone -m<email> -d<domain> -n --agree-tos

If you can't create one (most often because ports 80 and 443 are not available on your server, or you don't have adomain), a fallback script will generate a self-signed certificate for you inside the container. The only difference isa warning message about the certificate not being trusted (due to being self-signed) when logging in.

STEP 2: Running Your Container

Now that we are done with the certificate, you have to run the container.

NOTE: If you haven't generated a certificate in the previous step, remove volume mountings to cert paths in yourchosen method. As stated previously a self-signed certificate will be generated automatically with the downside ofuntrusted certificate warning at the logging phase.

OPTION 1: Docker Compose (Recommended)

I highly recommend using docker-compose for running your container, feel free to change the port byeditingdocer-compose.yml.

wget https://raw.githubusercontent.com/Pezhvak/docker-ocserv/develop/docker-compose.yml# IMPORTANT: Make sure you have updated the cert paths in volumes section# of the docker-compose.yml before running it.docker-compose up -d

OPTION 2: Docker Run Command

If you prefer to usedocker run all you have to do is to execute the following command:

docker run \    --name ocserv \    --restart=always \    -p 1342:443 \    -v$(pwd)/data/ocserv:/etc/ocserv/data \    -v$(pwd)/certs/live/<domain>/fullchain.pem:/etc/ocserv/server-cert.pem \    -v$(pwd)/certs/live/<domain>/privkey.pem:/etc/ocserv/server-key.pem \    pezhvak/ocserv

Your ocserv should be up and running now, you will have to create a user to be able to connect.

Updating

To update to the latest version, simply pull the image from docker hub.

For Docker Compose Installations

# This will pull the image from docker hubdocker-compose pull# Running 'up' again will detect the newer image and recreates the containerdocker-compose up -d

For Docker Run Installations

# Pull the image from docker hubdocker pull pezhvak/ocserv# Restart the containerdocker restart ocserv

Build Your Own Image

Although it's easier to use thepre-built image, it has its own downsides.namely, the limitations describedhere.

If you want to change the default configurations, you will have to build the image yourself, just clone the repo andchange the files you need.

Configuration files are stored in theconfig directory. you can also modifyscripts/docker-entrypoint.sh if needed.

1- Clone the repository to your server:

git clone https://github.com/Pezhvak/docker-ocserv.gitcd docker-ocserv

2- Build the image with your own settings, feel free to changeconfig/ocserv.conf to your liking:

docker build -t<image_name>.

3- Follow the steps ofUsing Built Image (Changepezhvak/ocserv to your own image name)

Usage

User Management

I have created a simple proxy shell (ocuser) in the image for easier interaction withocpasswd.

Create a new user

Add the specified user to the password file (You will be asked to provide a password after running the command)

dockerexec -it ocserv ash -c"ocuser create <username>"

Delete a User

Remove the specified user from the password file:

dockerexec ocserv ash -c"ocuser delete <username>"

Lock a User

Prevent the specified user from logging in:

dockerexec ocserv ash -c"ocuser lock <username>"

Unlock a User

Re-enable login for the specified user

dockerexec ocserv ash -c"ocuser unlock <username>"

Connecting to Server

Now that everything is set up and the user is created, you can connect to server using terminal or one of the availableapplications:

Using Terminal

Make sure you have installedopenconnect on your machine, you can do that in MacOS usingbrew install openconnect.

echo"<PASSWORD>"| sudo openconnect<DOMAIN>:<PORT> -u<USERNAME> --passwd-on-stdin

You can also create an alias in your~/.bash_profile (or~/.zshrc if you're using zsh) for easier access:

alias vpn:oc="echo <PASSWORD> | sudo openconnect <DOMAIN>:<PORT> -u <USERNAME> --passwd-on-stdin"

Using Clients

References

I appreciate these repositories which inspired me and helped me to put the pieces together:

About

A lightweight Alpine based ocserv Docker image.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp