DEV Community

Mike Buyco
Mike Buyco

Posted on

Building a Lua docker environment

Intro

I have a keen interest in containerization, a practice that has significantly streamlined my development workflow. Reflecting on my early days in programming around 2011-2012, I recall encountering a common issue when setting up local development environments. Specifically, during the installation of WAMP, I faced an error indicating that port 3306 (MySQL) was already in use. Upon investigation, I discovered that a previous installation of MySQL for a school project was the culprit, highlighting the challenges of managing dependencies and conflicting software configurations.

Motivation

Currently, I am embarking on a journey to learn Lua scripting to complement my son's endeavors in 3D modeling within the Roblox platform. This motivation stems from a desire to actively engage and support his interests, although finding the time amidst other responsibilities remains a challenge. Nevertheless, I am enthusiastic about delving into Lua scripting to enhance our collaborative projects.

Installation

To facilitate my exploration of Lua, I adopt a pragmatic approach by leveraging containerization with Docker to create a dedicated development environment. This method ensures isolation from existing system dependencies and simplifies setup and management.

First, let's build the project structure:

mkdir ~/learn-lua
cd ~/learn-lua
Enter fullscreen mode Exit fullscreen mode

Then, create a Dockerfile and our main.lua script:

touch Dockerfile
touch main.lua
Enter fullscreen mode Exit fullscreen mode

Dockerfile:

# Use a base image with Lua installed
FROM alpine:latest

# Install Lua and LuaRocks
RUN apk --update add lua5.3 lua5.3-dev luarocks5.3

# Optionally, you can install additional Lua packages using LuaRocks
# For example, to install LuaSocket:
# RUN luarocks-5.3 install luasocket

# Set the working directory
WORKDIR /app

# Copy your Lua scripts into the container
COPY . .

# Set the command to run your Lua script when the container starts
CMD ["lua5.3", "main.lua"]
Enter fullscreen mode Exit fullscreen mode

main.lua:

print("Hello, Lua!")
Enter fullscreen mode Exit fullscreen mode

Now to run the lua script:

docker build -t game-lua .
docker run -it --rm game-lua
Enter fullscreen mode Exit fullscreen mode

Time to learn more lua! I will update again soon :D

Top comments (0)