banner
冷板凳

冷板凳

🚀探索笔记和效率工具
twitter
telegram

Get Started with Docker: Personal Deployment Cases and Practical Tips for Beginners

image

What is Docker#

Docker is like a central cafeteria that gathers pre-made dishes from developers around the world. You can choose the corresponding pre-made dish for the program you want to run, just like ordering food.

These pre-made dishes contain everything needed to run the program, including software libraries, tools, and configurations, just like a complete runtime environment. Docker is like a microwave, you just need to put the pre-made dish in it, start heating, and you can easily run the program.

Whether it's open-source software or other complex programs, Docker allows you to start with just one click, without worrying about tedious configurations and environment setup.

Docker Installation#

Docker has a desktop client, and the installation is relatively simple. For Windows systems, you need to enable Hyper-V and proceed to the next step until it is completed. If there are no errors when opening the client, it means that the installation is successful.

image

image

If you encounter strange problems during the installation process, you may need to consider whether you are using a pirated version of Windows with a modified system.

Docker Applications#

Docker is like a huge software repository, which contains various pre-made software packages. Just like WeChat mini-programs, you can download and run them.

Personally, I use three applications with Docker: Memos, Lobehub, and Planka.

Lobehub is one of the best AI integration tools I have used, and it supports Vercel deployment. If you have installed Ollma locally, installing a Docker version of Lobe-Chat is a natural thing to do.

image

image

Memos is a lightweight note-taking service, similar to Flomo, where you can easily capture and share your wonderful ideas. It can be used as an offline friend circle.

image

Some scattered texts are recorded in Memos. When they can form an article, I transfer the fragments to Obsidian for integrated creation.

This Trello open-source version of the Kanban tool Planka is designed to meet the project management needs of individuals and teams. It has similar features to Trello, including boards, lists, and cards, but it is self-hosted, which means you have full control over your data and privacy.

image

image

Docker Tips#

I don't need to be proficient in using the Docker desktop client. Usually, I just open it to check if the containers are running, that's all.

Most operations are done using commands. However, in my actual work, I use no more than five commands.

I tried using the client for operations like deletion and pulling, and although they can be used, they are not user-friendly and can easily cause various small problems.

In my opinion, the best way is to combine a few commonly used commands with the client's visualization.

Pulling and Starting a Docker Project

Taking lobehub as an example, find the Docker installation link in the developer's GitHub project.

The first command, pull the image👇

docker pull lobehub/lobe-chat

image

Open CMD, copy and paste the link address, and press Enter.

image

After the project is installed, it needs to be started, which means downloading the image → starting the container. A car needs to be started to move, unless you don't want to push it on the road.

The second command, start the container👇

docker run -d -p 3210:3210 lobehub/lobe-chat

The convenience of Docker lies in improving luckiness. For ordinary people, Docker has already reduced the difficulty of using various system environments and configurations.

Usually, two commands are enough to complete the pulling and starting of a project.

At this time, open the Docker desktop client to see if the container is starting normally. Click the link to use it🎉

image

Use Memos offline to record inspirations, use LobeHut + Ollama's large models for text generation and translation, and use Planka to organize plans.

By mapping the local port to the public network and using port forwarding technology, you can access your Docker project from anywhere (home, mobile phone, other computers).

If you want to access your Docker project from outside the office, you need to use port forwarding, and your office computer must always be turned on.

I am used to using Docker locally. If I need external access, I will use Vercel or other free cloud deployment solutions.

Updating and Uninstalling Docker Projects

The core value of Docker lies in its free, offline, and secure features. However, it also has a major disadvantage, which is project updates, data migration, and other issues.

For example, if there are updates upstream of the project, how does Docker synchronize? When you need to switch computers, how do you migrate project data from one computer to another? How to cleanly uninstall a project?

When there are updates upstream of the project, there is usually a prompt in the project application. First, stop and remove the container, then pull the upstream updates to the local image, redeploy, and start the container.

To stop and remove the container, you can do it in the Docker client or use commands. If you use commands, you need to know the container name.

Stopping and removing the container using the client is simple and intuitive, just look at the icons.

image

Stopping and removing the container using the command line, first check which containers are there, determine the container name, and then stop and remove it.

docker ps -a

image

The command to stop and remove the container, taking memos as an example.

docker stop memos & docker rm memos

Both the client and command line operations are possible, choose one of them.

Similarly, the project image can be updated using the client's button or using commands.

If you use commands, it is the first pull command mentioned above.

If you use the client to update, click the Pull button for that image file.

image

After downloading the new version, the old version image can be deleted (Docker image pull generates a new image instead of overwriting the original image).

Now we need to restart the container. Remember, do not use the client for this operation, please use the command to start the container, such as the second command to start the container mentioned above.

In this way, the project is updated to the latest version and synchronized with the upstream. Usually, the old records will still be there, so it is recommended to back up the data before updating. For example, Memos has a note export function.

image

Starting the Project Container with Docker

If everything goes well, I believe you are already having fun.

When you turn off your computer after work and find that some programs cannot run the next day, it is because the containers did not start with Docker.

At this time, manually open the Docker client, select the container, and click the Start button. But it's too troublesome to manually start it every time you turn on the computer. I hope the container can start with Docker.

Two commands can solve this.

First, we need to determine whether the container is set to start automatically with the computer. If it is set to "Always", if not, it is set to "no". Taking memos as an example👇

docker inspect -f "{{ .HostConfig.RestartPolicy.Name }}" memos

image

If it is "no", execute the next command to set it to start automatically.

docker update --restart always memos

Then run the previous command again to check if it is set successfully. "Always" means it is set successfully.

Docker Command Extensions#

As you delve deeper into using Docker, more and more commands and operations can be confusing. If you cannot organize these commands and operations effectively, it will result in fragmented knowledge, making it difficult to master and use Docker.

My personal way of dealing with this is to save the commands in different categories. Look, isn't Planka, built with Docker, useful for this?

image

Building projects with Docker should be applications that are used frequently.

In addition, it is important to regularly clean up unnecessary images and containers. Images are the underlying foundation of containers, and containers are running instances. Too many unused images and containers can take up a lot of storage space and may slow down the system.

Therefore, avoid installing many rarely used projects, which will unnecessarily consume computer performance.

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.