* Quote all vars, remove useless echo/sub-shell, add shebands, fail on unset vars, enable pipefail, formatting
* Add CI including linting via hadolint nad shellcheck
* Update all base images to tag 3.9
* Switch to maintainer labels
* Quote vars
* Remove commented code
* Ignore if the folder exists
When using named containers in docker compose, it creates them with root and the factorio docker container fails to start because it doesn't have write permissions. Reproduce by using the following docker-compose file:
version: '3.2'
services:
server:
image: dtandersen/factorio:0.16.7
volumes:
- logs:/var/log
- data:/factorio
ports:
- "34197:34197/udp"
- "27015:27015/tcp"
volumes:
logs:
data:
With this proposed change, the /factorio folder is created *before* it is made a volume. This causes docker to correctly preserve the permissions, the docker-compose file above works now.
This is related to https://github.com/dtandersen/docker_factorio_server/issues/91 and maybe also makes https://github.com/dtandersen/docker_factorio_server/pull/99 obsolete.
When starting the container with `docker run -d -u $(id -u factorio):$(id -g factorio) ...`, permission is denied upon trying to create `/opt/factorio/.lock` file.
This permission tweak will allow caller to pass desired user from host to container such that the permissions are retained correctly when games are saved to the mount.
Also, it just feels wrong to run factorio as root, container or not. :)
*`0.x` - highest version in a branch: may be experimental.
*`latest` - most up-to-date version (may be experimental).
*`stable` - version declared stable on [factorio.com](https://www.factorio.com).
*`0.x` - latest version in a branch.
*`0.x.y` - a specific version.
*`0.x-dev` - whatever is in master for that version.
@ -28,24 +29,30 @@ NOTE: This is only the server. The game is available at [factorio.com](https://w
## Quick Start
Run the server to create the necessary folder structure and configuration files. For this example data is stored in `/tmp/factorio`.
Run the server to create the necessary folder structure and configuration files. For this example data is stored in `/opt/factorio`.
```
docker run -d -p 34197:34197/udp -p 27015:27015/tcp \
-v /tmp/factorio:/factorio \
sudo mkdir -p /opt/factorio
sudo chown 845:845 /opt/factorio
sudo docker run -d \
-p 34197:34197/udp \
-p 27015:27015/tcp \
-v /opt/factorio:/factorio \
--name factorio \
--restart=always \
dtandersen/factorio
--restart=always \
factoriotools/factorio
```
For those new to Docker, here is an explanation of the options:
*`-d` - Run as a daemon ("detached").
*`-p` - Expose ports.
*`-v` - Mount `/tmp/factorio` on the local file system to `/factorio` in the container.
*`-v` - Mount `/opt/factorio` on the local file system to `/factorio` in the container.
*`--restart` - Restart the server if it crashes and at system start
*`--name` - Name the container "factorio" (otherwise it has a funny random name).
The `chown` command is needed because in 0.16+, we no longer run the game server as root for security reasons, but rather as a 'factorio' user with user id 845. The host must therefore allow these files to be written by that user.
Check the logs to see what happened:
```
@ -58,7 +65,7 @@ Stop the server:
docker stop factorio
```
Now there's a `server-settings.json` file in the folder `/tmp/factorio/config`. Modify this to your liking and restart the server:
Now there's a `server-settings.json` file in the folder `/opt/factorio/config`. Modify this to your liking and restart the server:
```
docker start factorio
@ -67,9 +74,34 @@ docker start factorio
Try to connect to the server. Check the logs if it isn't working.
## Console
To issue console commands to the server, start the server in interactive mode with `-it`. Open the console with `docker attach` and then type commands.
docker run -d -it \
--name factorio \
factoriotools/factorio
docker attach factorio
## Upgrading
Before upgrading backup the save. It's easy to make a save in the client.
Ensure `-v` was used to run the server so the save is outside of the Docker container. The `docker rm` command completely destroys the container, which includes the save if it isn't stored in an data volume.
Delete the container and refresh the image:
docker stop factorio
docker rm factorio
docker pull factoriotools/factorio
Now run the server as before. In about a minute the new version of Factorio should be up and running, complete with saves and config!
## Saves
A new map named `_autosave1.zip` is generated the first time the server is started. The `map-gen-settings.json` file in `/tmp/factorio/config`is used for the map settings. On subsequent runs the newest save is used.
A new map named `_autosave1.zip` is generated the first time the server is started. The `map-gen-settings.json` and `map-settings.json` files in `/opt/factorio/config`are used for the map settings. On subsequent runs the newest save is used.
To load an old save stop the server and run the command `touch oldsave.zip`. This resets the date. Then restart the server. Another option is to delete all saves except one.
@ -81,13 +113,97 @@ To generate a new map stop the server, delete all of the saves and restart the s
Copy mods into the mods folder and restart the server.
## Scenarios
If you want to launch a scenario from a clean start (not from a saved map) you'll need to start the docker image from an alternate entrypoint. To do this, use the example entrypoint file stored in the /factorio/entrypoints directory in the volume, and launch the image with the following syntax. Note that this is the normal syntax with the addition of the --entrypoint setting AND the additional argument at the end, which is the name of the Scenario in the Scenarios folder.
```
docker run -d \
-p 34197:34197/udp \
-p 27015:27015/tcp \
-v /opt/factorio:/factorio \
--name factorio \
--restart=always \
--entrypoint "/scenario.sh" \
factoriotools/factorio \
MyScenarioName
```
## Converting Scenarios to Regular Maps
If you would like to export your scenario to a saved map, you can use the example entrypoint similar to the Scenario usage above. Factorio will run once, converting the Scenario to a saved Map in your saves directory. A restart of the docker image using the standard options will then load that map, just as if the scenario were just started by the Scenarios example noted above.
```
docker run -d \
-p 34197:34197/udp \
-p 27015:27015/tcp \
-v /opt/factorio:/factorio \
--name factorio \
--restart=always \
--entrypoint "/scenario2map.sh" \
factoriotools/factorio
MyScenarioName
```
## RCON
Set the RCON password in the `rconpw` file. A random password is generated if `rconpw` doesn't exist.
To change the password stop the server, modify `rconpw`, and restart the server.
To change the password, stop the server, modify `rconpw`, and restart the server.
To "disable" RCON don't expose port 27015, i.e. start the server with `-p 34197:34197/udp` instead of `-P`. RCON still runs, but nobody is able to connect to it.
To "disable" RCON don't expose port 27015, i.e. start the server without`-p 27015:27015/tcp`. RCON is still running, but nobody can to connect to it.
## Whitelisting (0.15.3+)
Create file `config/server-whitelist.json` and add the whitelisted users.
[
"you",
"friend"
]
## Banlisting (0.17.1+)
Create file `config/server-banlist.json` and add the banlisted users.
[
"bad_person",
"other_bad_person"
]
## Adminlisting (0.17.1+)
Create file `config/server-adminlist.json` and add the adminlisted users.
[
"you",
"friend"
]
## Customize configuration files (0.17.x+)
Out-of-the box, factorio does not support environment variables inside the configuration files. A workaround is the usage of `envsubst` which generates the configuration files dynamically during startup from environment variables set in docker-compose:
The `server-settings.json` file may then contain the variable references like this:
"name": "${INSTANCE_NAME}",
"description": "${INSTANCE_DESC}",
# Container Details
@ -103,28 +219,108 @@ The philosophy is to [keep it simple](http://wiki.c2.com/?KeepItSimple).
To keep things simple, the container uses a single volume mounted at `/factorio`. This volume stores configuration, mods, and saves.
The files in this volume should be owned by the factorio user, uid 845.
factorio
|-- config
| |-- map-gen-settings.json
| |-- map-settings.json
| |-- rconpw
| `-- server-settings.json
| |-- server-adminlist.json
| |-- server-banlist.json
| |-- server-settings.json
| `-- server-whitelist.json
|-- mods
| `-- fancymod.zip
`-- saves
`-- _autosave1.zip
## Docker Compose
[Docker Compose](https://docs.docker.com/compose/install/) is an easy way to run Docker containers.
First get a [docker-compose.yml](https://github.com/factoriotools/factorio-docker/blob/master/0.17/docker-compose.yml) file. To get it from this repository:
Now cd to the directory with docker-compose.yml and run:
```
sudo mkdir -p /opt/factorio
sudo chown 845:845 /opt/factorio
sudo docker-compose up -d
```
## Ports
*`34197/udp` - Factorio clients (required).
*`34197/udp` - Game server (required).
*`27015/tcp` - RCON (optional).
## Environment Variables
*`PORT` - Start the server on an alterate port, .e.g. `docker run -e "PORT=34198"`.
*`PORT` (0.15+) - Start the server on an alternate port, .e.g. `docker run -e "PORT=34198"`.
*`RCON_PORT` (0.16+) - Start the RCON on an alternate port, .e.g. `docker run -e "RCON_PORT=34198"`.
## LAN Games
Ensure the `lan` setting in server-settings.json is `true`.
```
"visibility":
{
"public": false,
"lan": true
},
```
Start the container with the `--network=host` option so clients can automatically find LAN games. Refer to the Quick Start to create the `/opt/factorio` directory.
```
sudo docker run -d \
--network=host \
-p 34197:34197/udp \
-p 27015:27015/tcp \
-v /opt/factorio:/factorio \
--name factorio \
--restart=always \
factoriotools/factorio
```
## Vagrant
[Vagrant](https://www.vagrantup.com/) is a easy way to setup a virtual machine (VM) to run Docker. The [Factorio Vagrant box repository](https://github.com/dtandersen/factorio-lan-vagrant) contains a sample Vagrantfile.
For LAN games the VM needs an internal IP in order for clients to connect. One way to do this is with a public network. The VM uses DHCP to acquire an IP address. The VM must also forward port 34197.
If you're looking for a simple way to deploy this to the Amazon Web Services Cloud, check out the [Factorio Server Deployment (CloudFormation) repository](https://github.com/m-chandler/factorio-spot-pricing). This repository contains a CloudFormation template that will get you up and running in AWS in a matter of minutes. Optionally it uses Spot Pricing so the server is very cheap, and you can easily turn it off when not in use.
## Troubleshooting
**My server is listed in the server browser, but nobody can connect**
@ -140,9 +336,14 @@ To fix the incorrect port, start the Docker service with the `--userland-proxy=f
Use the `PORT` environment variable to start the server on the a different port, .e.g. `docker run -e "PORT=34198"`. This changes the source port on the packets used for port detection. `-p 34198:34197` works fine for private servers, but the server browser detects the wrong port.
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.